diff options
author | Nicolas Petton <nicolas@petton.fr> | 2015-10-20 00:11:30 +0200 |
---|---|---|
committer | Nicolas Petton <nicolas@petton.fr> | 2015-10-20 00:39:27 +0200 |
commit | 04d604e0553f76ea9ab266cf44c1d3f89f8bd2f0 (patch) | |
tree | 2f5b54b355421705fd5dfec28bd9f88d16165e26 /lisp/emacs-lisp | |
parent | b911b4b25db93c8b574a5dc6f1258893b4aa18c4 (diff) | |
download | emacs-04d604e0553f76ea9ab266cf44c1d3f89f8bd2f0.tar.gz emacs-04d604e0553f76ea9ab266cf44c1d3f89f8bd2f0.tar.bz2 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/emacs-lisp')
-rw-r--r-- | lisp/emacs-lisp/seq.el | 15 |
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 @@ ;; Author: Nicolas Petton <nicolas@petton.fr> ;; Keywords: sequences -;; Version: 2.0 +;; Version: 2.1 ;; Package: seq ;; Maintainer: emacs-devel@gnu.org @@ -294,12 +294,23 @@ found or not." count)) (cl-defgeneric seq-contains (seq elt &optional testfn) - "Return the first element in SEQ that equals to ELT. + "Return the first element in SEQ that is equal to ELT. Equality is defined by TESTFN if non-nil or by `equal' if nil." (seq-some (lambda (e) (funcall (or testfn #'equal) elt e)) seq)) +(cl-defgeneric seq-position (seq elt &optional testfn) + "Return the index of the first element in SEQ that is equal to ELT. +Equality is defined by TESTFN if non-nil or by `equal' if nil." + (let ((index 0)) + (catch 'seq--break + (seq-doseq (e seq) + (when (funcall (or testfn #'equal) e elt) + (throw 'seq--break index)) + (setq index (1+ index))) + nil))) + (cl-defgeneric seq-uniq (seq &optional testfn) "Return a list of the elements of SEQ with duplicates removed. TESTFN is used to compare elements, or `equal' if TESTFN is nil." |