Side effects
Functions iterating over lists for side effect only.
Function: -each (list fn)
Call fn on each element of list. Return nil; this function is intended for side effects.
Its anaphoric counterpart is --each.
For access to the current element’s index in list, see -each-indexed (see -each-indexed).
(let (l) (-each '(1 2 3) (lambda (x) (push x l))) l)
⇒ (3 2 1)(let (l) (--each '(1 2 3) (push it l)) l)
⇒ (3 2 1)(-each '(1 2 3) #'identity)
⇒ nilFunction: -each-while (list pred fn)
Call fn on each item in list, while (pred item) is non-nil. Once an item is reached for which pred returns nil, fn is no longer called. Return nil; this function is intended for side effects.
Its anaphoric counterpart is --each-while.
(let (l) (-each-while '(2 4 5 6) #'even? (lambda (x) (push x l))) l)
⇒ (4 2)(let (l) (--each-while '(1 2 3 4) (< it 3) (push it l)) l)
⇒ (2 1)(let ((s 0)) (--each-while '(1 3 4 5) (< it 5) (setq s (+ s it))) s)
⇒ 8Function: -each-indexed (list fn)
Call fn on each index and element of list. For each item at index in list, call (funcall fn index item). Return nil; this function is intended for side effects.
See also: -map-indexed (see -map-indexed).
(let (l) (-each-indexed '(a b c) (lambda (i x) (push (list x i) l))) l)
⇒ ((c 2) (b 1) (a 0))(let (l) (--each-indexed '(a b c) (push (list it it-index) l)) l)
⇒ ((c 2) (b 1) (a 0))(let (l) (--each-indexed () (push it l)) l)
⇒ ()Function: -each-r (list fn)
Call fn on each element of list in reversed order. Return nil; this function is intended for side effects.
Its anaphoric counterpart is --each-r.
(let (l) (-each-r '(1 2 3) (lambda (x) (push x l))) l)
⇒ (1 2 3)(let (l) (--each-r '(1 2 3) (push it l)) l)
⇒ (1 2 3)(-each-r '(1 2 3) #'identity)
⇒ nilFunction: -each-r-while (list pred fn)
Call fn on each item in reversed list, while (pred item) is non-nil. Once an item is reached for which pred returns nil, fn is no longer called. Return nil; this function is intended for side effects.
Its anaphoric counterpart is --each-r-while.
(let (l) (-each-r-while '(2 4 5 6) #'even? (lambda (x) (push x l))) l)
⇒ (6)(let (l) (--each-r-while '(1 2 3 4) (>= it 3) (push it l)) l)
⇒ (3 4)(let ((s 0)) (--each-r-while '(1 2 3 5) (> it 1) (setq s (+ s it))) s)
⇒ 10Function: -dotimes (num fn)
Call fn num times, presumably for side effects. fn is called with a single argument on successive integers running from 0, inclusive, to num, exclusive. fn is not called if num is less than 1.
This function’s anaphoric counterpart is --dotimes.
(let (s) (-dotimes 3 (lambda (n) (push n s))) s)
⇒ (2 1 0)(let (s) (-dotimes 0 (lambda (n) (push n s))) s)
⇒ ()(let (s) (--dotimes 5 (push it s)) s)
⇒ (4 3 2 1 0)