Function: seq-position

seq-position is a byte-compiled function defined in seq.el.gz.

Signature

(seq-position SEQUENCE ELT &optional TESTFN)

Documentation

Return the (zero-based) index of the first element in SEQUENCE "equal" to ELT.

"Equality" is defined by the function TESTFN, which defaults to equal.

Other relevant functions are documented in the sequence and string groups.

View in manual

Shortdoc

;; string
(seq-position "foobarzot" ?z)
    => 6
;; sequence
(seq-position '(a b c) 'c)
    => 2

Implementations

(seq-position 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-position (sequence elt &optional testfn)
  "Return the (zero-based) index of the first element in SEQUENCE \"equal\" to ELT.
\"Equality\" is defined by the function TESTFN, which defaults to `equal'."
  (let ((index 0))
    (catch 'seq--break
      (seq-doseq (e sequence)
        (when (funcall (or testfn #'equal) e elt)
          (throw 'seq--break index))
        (setq index (1+ index)))
      nil)))