aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
Diffstat (limited to 'lisp')
-rw-r--r--lisp/emacs-lisp/seq.el15
1 files changed, 13 insertions, 2 deletions
diff --git a/lisp/emacs-lisp/seq.el b/lisp/emacs-lisp/seq.el
index ce6645a099a..f5189c7dc97 100644
--- a/lisp/emacs-lisp/seq.el
+++ b/lisp/emacs-lisp/seq.el
@@ -4,7 +4,7 @@
4 4
5;; Author: Nicolas Petton <nicolas@petton.fr> 5;; Author: Nicolas Petton <nicolas@petton.fr>
6;; Keywords: sequences 6;; Keywords: sequences
7;; Version: 2.0 7;; Version: 2.1
8;; Package: seq 8;; Package: seq
9 9
10;; Maintainer: emacs-devel@gnu.org 10;; Maintainer: emacs-devel@gnu.org
@@ -294,12 +294,23 @@ found or not."
294 count)) 294 count))
295 295
296(cl-defgeneric seq-contains (seq elt &optional testfn) 296(cl-defgeneric seq-contains (seq elt &optional testfn)
297 "Return the first element in SEQ that equals to ELT. 297 "Return the first element in SEQ that is equal to ELT.
298Equality is defined by TESTFN if non-nil or by `equal' if nil." 298Equality is defined by TESTFN if non-nil or by `equal' if nil."
299 (seq-some (lambda (e) 299 (seq-some (lambda (e)
300 (funcall (or testfn #'equal) elt e)) 300 (funcall (or testfn #'equal) elt e))
301 seq)) 301 seq))
302 302
303(cl-defgeneric seq-position (seq elt &optional testfn)
304 "Return the index of the first element in SEQ that is equal to ELT.
305Equality is defined by TESTFN if non-nil or by `equal' if nil."
306 (let ((index 0))
307 (catch 'seq--break
308 (seq-doseq (e seq)
309 (when (funcall (or testfn #'equal) e elt)
310 (throw 'seq--break index))
311 (setq index (1+ index)))
312 nil)))
313
303(cl-defgeneric seq-uniq (seq &optional testfn) 314(cl-defgeneric seq-uniq (seq &optional testfn)
304 "Return a list of the elements of SEQ with duplicates removed. 315 "Return a list of the elements of SEQ with duplicates removed.
305TESTFN is used to compare elements, or `equal' if TESTFN is nil." 316TESTFN is used to compare elements, or `equal' if TESTFN is nil."