Elisp: Sequence Find

By Xah Lee. Date: . Last updated: .

Check If Item Exist

seq-contains

(seq-contains SEQUENCE ELT &optional TESTFN)

check if item exist by equality test. 〔see Elisp: Equality Test

(seq-contains [3 4 5] 5  )
;; 5
seq-position

(seq-position SEQUENCE ELT &optional TESTFN)

return the position of the first occurrence, if exist.

(seq-position [3 4 5 4] 4 )
;; 1
seq-positions

(seq-positions SEQUENCE ELT &optional TESTFN)

check if item exist by equality test, and return a list of positions.

(seq-positions [3 4 5 4] 4 )
;; (1 3)

Find by Criterion, Count

seq-find

(seq-find PRED SEQUENCE &optional DEFAULT)

return first item a function returns true.

(setq xx [ "once" "upon" "a" "time" ])

(seq-find (lambda (x) (string-match "p" x)) xx)
;; "upon"
seq-count
(seq-find PRED SEQUENCE &optional DEFAULT)

return count where a function return true.

(setq xx [ "once" "upon" "a" "time" ])

(seq-count (lambda (x) (string-match "e" x)) xx)
;; 2

Elisp, Check Element Exist

Elisp, sequence functions