mirror of
git://git.sv.gnu.org/emacs.git
synced 2025-12-05 22:20:24 -08:00
Add new sequence function 'seq-union'
* lisp/emacs-lisp/seq.el (seq-union): New function. * doc/lispref/sequences.texi (Sequence Functions): * lisp/emacs-lisp/shortdoc.el (sequence): Document above new function. * test/lisp/emacs-lisp/seq-tests.el (test-seq-union): New test.
This commit is contained in:
parent
fc10e7fe5f
commit
0cf0a2b986
5 changed files with 66 additions and 0 deletions
|
|
@ -467,6 +467,17 @@ negative integer or 0, nil is returned."
|
|||
(setq sequence (seq-drop sequence n)))
|
||||
(nreverse result))))
|
||||
|
||||
(cl-defgeneric seq-union (sequence1 sequence2 &optional testfn)
|
||||
"Return a list of all elements that appear in either SEQUENCE1 or SEQUENCE2.
|
||||
Equality is defined by TESTFN if non-nil or by `equal' if nil."
|
||||
(let ((accum (lambda (acc elt)
|
||||
(if (seq-contains-p acc elt testfn)
|
||||
acc
|
||||
(cons elt acc)))))
|
||||
(seq-reverse
|
||||
(seq-reduce accum sequence2
|
||||
(seq-reduce accum sequence1 '())))))
|
||||
|
||||
;;;###autoload
|
||||
(cl-defgeneric seq-intersection (sequence1 sequence2 &optional testfn)
|
||||
"Return a list of the elements that appear in both SEQUENCE1 and SEQUENCE2.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue