Function: seq-positions
seq-positions is a byte-compiled function defined in seq.el.gz.
Signature
(seq-positions SEQUENCE ELT &optional TESTFN)
Documentation
Return list of indices of SEQUENCE elements for which TESTFN returns non-nil.
TESTFN is a two-argument function which is called with each element of
SEQUENCE as the first argument and ELT as the second.
TESTFN defaults to equal.
The result is a list of (zero-based) indices.
Other relevant functions are documented in the sequence group.
Probably introduced at or before Emacs version 29.1.
Shortdoc
;; sequence
(seq-positions '(a b c a d) 'a)
=> (0 3)
(seq-positions '(a b c a d) 'z)
=> nil
(seq-positions '(11 5 7 12 9 15) 10 #'>=)
=> (0 3 5)
Implementations
(seq-positions SEQUENCE ELT &optional TESTFN) in `seq.el'.
Undocumented
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/seq.el.gz
;;;###autoload
(cl-defgeneric seq-positions (sequence elt &optional testfn)
"Return list of indices of SEQUENCE elements for which TESTFN returns non-nil.
TESTFN is a two-argument function which is called with each element of
SEQUENCE as the first argument and ELT as the second.
TESTFN defaults to `equal'.
The result is a list of (zero-based) indices."
(let ((result '()))
(seq-do-indexed
(lambda (e index)
(when (funcall (or testfn #'equal) e elt)
(push index result)))
sequence)
(nreverse result)))