Elisp: Sequence. some, every (conditional exit)
Foreach with break, get the element that breaks
seq-some-
(seq-some PRED SEQUENCE)- Apply a function PRED to each sequence element in order.
- Exit loop when PRED return true. Return that value.
- If no result is true, return false.
🟢 tip: This is useful as functional programing style of doing a loop with break, especially when you need to know which element breaks the condition.
;; demo of seq-some (seq-some (lambda (x) (if (eq 5 x) x nil )) [4 5 6]) ;; 5
Foreach with Break
seq-every-p-
(seq-every-p PRED SEQUENCE)- Apply a function PRED to each sequence element in order.
- Exit loop when PRED return false.
- Return true if every result is true, else false.
🟢 tip: This is useful as functional programing style of doing a loop with break, and you do not need to know which element breaks the condition.
;; demo of seq-every-p (seq-every-p (lambda (x) (if (eq (mod x 2) 0) x nil )) [4 5 6]) ;; nil