X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/8932f000a3cf1c0649ae2f4cb14a6b43d6e09e12..54a75e6f7c580d5821e8b6f695b3c51240f966cd:/packages/seq/seq.el diff --git a/packages/seq/seq.el b/packages/seq/seq.el index 3fd7cf735..58f69032c 100644 --- a/packages/seq/seq.el +++ b/packages/seq/seq.el @@ -4,7 +4,7 @@ ;; Author: Nicolas Petton ;; Keywords: sequences -;; Version: 1.9 +;; Version: 1.11 ;; Package: seq ;; Maintainer: emacs-devel@gnu.org @@ -165,8 +165,7 @@ If SEQ is empty, return INITIAL-VALUE and FUNCTION is not called." acc))) (defun seq-some (pred seq) - "Return non-nil if (PRED element) is non-nil for any element in SEQ, nil otherwise. -If so, return the non-nil value returned by PRED." + "Return the first value for which if (PRED element) is non-nil for in SEQ." (catch 'seq--break (seq-doseq (elt seq) (let ((result (funcall pred elt))) @@ -224,6 +223,17 @@ Equality is defined by TESTFN if non-nil or by `equal' if nil." (funcall (or testfn #'equal) elt e)) seq)) +(defun 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))) + (defun 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."