Elisp: Sequence Iteration, Conditional Exit

By Xah Lee. Date: .

Foreach with Break, Get F Return Value

seq-some

Apply a function f to each sequence element in order, stop and return the first f result that's true. Else, return nil.

💡 TIP: This is useful as functional form of loop with break, especially if you want the return value of f.

;; demo of seq-some
(seq-some
 (lambda (x)
   (if (eq 5 x)
       x
     nil
     ))
 [4 5 6])
;; 5

Foreach with Break

seq-every-p

Apply a function f to each sequence element in order, return true if every result is true. As soon as a value is false, the loop stops.

💡 TIP: This is useful as functional form of loop with break, and you no need any return value.

;; demo of seq-every-p
(seq-every-p
 (lambda (x)
   (if (eq (mod x 2) 0)
       x
     nil
     ))
 [4 5 6])
;; nil

Elisp, sequence functions