aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorNicolas Petton2015-10-20 00:11:30 +0200
committerNicolas Petton2015-10-20 00:39:27 +0200
commit04d604e0553f76ea9ab266cf44c1d3f89f8bd2f0 (patch)
tree2f5b54b355421705fd5dfec28bd9f88d16165e26 /lisp
parentb911b4b25db93c8b574a5dc6f1258893b4aa18c4 (diff)
downloademacs-04d604e0553f76ea9ab266cf44c1d3f89f8bd2f0.tar.gz
emacs-04d604e0553f76ea9ab266cf44c1d3f89f8bd2f0.zip
New function seq-position
* lisp/emacs-lisp/seq.el (seq-position): New function. * test/automated/seq-tests.el: New tests for seq-position. * doc/lispref/sequences.texi: Add documentation for `seq-position'.
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."