This package is now both in Emacs 25.1 and ELPA. Further development will only happen there.
Do not send pull requests or open issues here (use M-x report-emacs-bug instead).
seq.el provides Sequence manipulation functions that complement basic
functions provided by subr.el. The library is included in Emacs 25.
All functions are prefixed with seq-.
All provided functions work on lists, strings and vectors.
Functions taking a predicate or iterating over a sequence using a function as argument take the function as their first argument and the sequence as their second argument. All other functions take the sequence as their first argument.
All functions are tested in test/seq-tests.el
Note: The version 2 of seq.el is maintained in the Emacs git repository, please consider sending patches there.
seq.el provides the following functions:
-
seq-dropseq nThis function returns a sequence of all but the first
nelements of the sequenceseq.seqmay be a list, vector or string andnmust be an integer. The result is the same type of sequence asseq.If
nis a negative integer or zero,seqis returned. -
seq-takeseq nThis function returns a sequence of the first
nelements ofseq.seqmay be a list, vector or string andnmust be an integer. The result is the same type of sequence asseq.If
nis a negative integer or zero, an empty sequence is returned. -
seq-take-whilepred seqThis function returns a sub-sequence of the successive elements of
seqfor which callingpredwith that element returns non-nil.predmust be a one-argument function andseqmay be a list, vector or string. The result is the same type of sequence asseq.If evaluating
predwith the first element ofseqas argument returnsnil, an empty sequence is returned. -
seq-drop-whilepred seqThis function returns a sub-sequence of
seqfrom the first element for which callingpredwith that element returnsnil.predmust be a one-argument function andseqmay be a list, vector or string. The result is the same type of sequence asseq.If evaluating
predwith every element ofseqreturnsnil,seqis returned. -
seq-filterpred seqThis function returns a list of all the elements in
seqfor which callingpredwith that element returns non-nil.predmust be a one-argument function andseqmay be a list, vector or string. -
seq-mapfunction seqThis function returns the result of applying
functionto each element ofseq. The returned value is a list.functionmust be a one-argument function andseqmay be a list, vector or string. -
seq-mapnfunction &rest seqsThis function returns the result of applying
functionto each element of allseqs. The returned value is a list.The arity of FUNCTION must match the number of SEQS, and the mapping stops on the shortest sequence.
-
seq-removepred seq This function returns a list of all the elements inseqfor which callingpredwith that element returnsnil.predmust be a one-argument function andseqmay be a list, vector or string. -
seq-reducefunction seq initial-value This function returns the result of callingfunctionwithinitial-valueand the first element ofseq, then callingfunctionwith that result and the second element ofseq, then with that result and the third element ofseq, etc.functionmust be a two-arguments function andseqmay be a list, vector or string.If
seqis empty,initial-valueis returned andfunctionis not called. -
seq-somepred seq This function returns non-nil if callingpredwith any element ofseqreturns non-nil. If so, the returned value is the value returned byseq.predmust be a one-argument function andseqmay be a list, vector or string. -
seq-findpred seq &optional default This function returns the first element for whichpredreturns non-nil inseq. If no element matchespref,defaultis returned.Note that this function has an ambiguity if the found element is identical to
default, as it cannot be known if an element was found or not. -
seq-every-ppred seq This function returns non-nil if successively callingpredwith each element ofseqalways returns non-nil,nilotherwise.predmust be a one-argument function andseqmay be a list, vector or string. -
seq-empty-pseq This function returns non-nil if the sequenceseqis empty,nilotherwise.seqmay be a list, vector or string. -
seq-countpred seq This function returns the number of elements inseqfor which callingpredwith that element returns non-nil.predmust be a one-argument function andseqmay be a list, vector or string. -
seq-sortpred seq This function returns a sorted sequence of the elements ofseq, comparing its elements withpred. Called with two elements ofseq,predshould return non-nil if the first element should sort before the second.predmust be a two-arguments function,seqmay be a list, vector or string.The result is a sequence of the same type as SEQ.
-
seq-containsseq elt testfn This function returns the first element inseqthat equals toelt.Equality is defined by
testfnif non-nil or byequalifnil.seqmay be a list, vector or string. -
seq-positionseq elt testfn This function returns the index of the first element inseqthat is equal toelt. Equality is defined bytestfnif non-nil or byequalif nil."seqmay be a list, vector or string. -
seq-uniqseq testfn This function returns a list of the elements ofseqwith duplicates removed.testfnis used to compare elements, orequaliftestfnisnil.testfnmust be a two-argument function ornilandseqmay be a list, vector or string. -
seq-subseqseq start &optional end This function returns a sub-sequence ofseqfromstarttoend. Ifendis omitted, it default to the length ofseq. Ifstartorendis negative, it counts from the end ofseq.seqmay be a list, vector or string. The result is the same type of sequence asseq. -
seq-concatenatetype &rest seqs This function returns a sequence made of the concatenation ofseqs. The result is a sequence of typetype.typemay be one of the following symbols:vector,listorstring. -
seq-mapcatfunction sequence &optional type This function returns the result of applyingseq-concatenateto the result of applyingfunctionto each element ofsequence. The result is a sequence of typetype, or a list iftypeis nil. -
seq-partitionsequence n This function returns a list of the elements ofsequencegrouped into sub-sequences of lengthn. The last sequence may contain less elements thann.nmust be an integer. Ifnis a negative integer or 0, nil is returned. -
seq-group-byfunction sequence This function separates the elements ofsequenceinto an alist whose keys are the result of applyingfunctionto each element ofsequence. Keys are compared usingequal. -
seq-intersectionseq1 seq2 &optional testfn Return a list of the elements that appear in bothseq1andseq2. Equality is defined by TESTFN if non-nil or byequalif nil. -
seq-differenceseq1 seq2 &optional testfn Return a list of the elements that appear in bothseq1but not inseq2. Equality is defined by TESTFN if non-nil or byequalif nil. -
seq-doseq(var seq [result]) body... This macro is likedolist, except thatseqcan be a list, vector or string.seq-doseqis primarily useful for side-effects. -
seq-letargs &rest body Bind the variables in ARGS to the elements of SEQ then evaluate BODY. ARGS can also include the `&rest' marker followed by a variable name to be bound to the rest of SEQ.
Since this library is in Emacs 25, contributors must have signed the Emacs Copyright assignment.
Fetch dependencies:
$ cd /path/to/seq.el
$ cask
Run the tests:
$ ./run-tests.sh