From 04d604e0553f76ea9ab266cf44c1d3f89f8bd2f0 Mon Sep 17 00:00:00 2001 From: Nicolas Petton Date: Tue, 20 Oct 2015 00:11:30 +0200 Subject: 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'. --- lisp/emacs-lisp/seq.el | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'lisp/emacs-lisp') 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 ;; 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." -- cgit v1.2.3