List to list
Functions returning a modified copy of the input list.
Function: -keep (fn list)
Return a new list of the non-nil results of applying fn to each item in list. Like -filter (see -filter), but returns the non-nil results of fn instead of the corresponding elements of list.
Its anaphoric counterpart is --keep.
(-keep #'cdr '((1 2 3) (4 5) (6)))
⇒ ((2 3) (5))(-keep (lambda (n) (and (> n 3) (* 10 n))) '(1 2 3 4 5 6))
⇒ (40 50 60)(--keep (and (> it 3) (* 10 it)) '(1 2 3 4 5 6))
⇒ (40 50 60)Function: -concat (&rest sequences)
Concatenate all sequences and make the result a list. The result is a list whose elements are the elements of all the arguments. Each argument may be a list, vector or string.
All arguments except the last argument are copied. The last argument is just used as the tail of the new list. If the last argument is not a list, this results in a dotted list.
As an exception, if all the arguments except the last are nil, and the last argument is not a list, the return value is that last argument unaltered, not a list.
(-concat '(1))
⇒ (1)(-concat '(1) '(2))
⇒ (1 2)(-concat '(1) '(2 3) '(4))
⇒ (1 2 3 4)Function: -flatten (l)
Take a nested list l and return its contents as a single, flat list.
Note that because nil represents a list of zero elements (an empty list), any mention of nil in l will disappear after flattening. If you need to preserve nils, consider -flatten-n (see -flatten-n) or map them to some unique symbol and then map them back.
Conses of two atoms are considered "terminals", that is, they aren’t flattened further.
See also: -flatten-n (see -flatten-n)
(-flatten '((1)))
⇒ (1)(-flatten '((1 (2 3) (((4 (5)))))))
⇒ (1 2 3 4 5)(-flatten '(1 2 (3 . 4)))
⇒ (1 2 (3 . 4))Function: -flatten-n (num list)
Flatten num levels of a nested list.
See also: -flatten (see -flatten)
(-flatten-n 1 '((1 2) ((3 4) ((5 6)))))
⇒ (1 2 (3 4) ((5 6)))(-flatten-n 2 '((1 2) ((3 4) ((5 6)))))
⇒ (1 2 3 4 (5 6))(-flatten-n 3 '((1 2) ((3 4) ((5 6)))))
⇒ (1 2 3 4 5 6)Function: -replace (old new list)
Replace all old items in list with new.
Elements are compared using equal.
See also: -replace-at (see -replace-at)
(-replace 1 "1" '(1 2 3 4 3 2 1))
⇒ ("1" 2 3 4 3 2 "1")(-replace "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo"))
⇒ ("a" "nice" "bar" "sentence" "about" "bar")(-replace 1 2 nil)
⇒ nilFunction: -replace-first (old new list)
Replace the first occurrence of old with new in list.
Elements are compared using equal.
See also: -map-first (see -map-first)
(-replace-first 1 "1" '(1 2 3 4 3 2 1))
⇒ ("1" 2 3 4 3 2 1)(-replace-first "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo"))
⇒ ("a" "nice" "bar" "sentence" "about" "foo")(-replace-first 1 2 nil)
⇒ nilFunction: -replace-last (old new list)
Replace the last occurrence of old with new in list.
Elements are compared using equal.
See also: -map-last (see -map-last)
(-replace-last 1 "1" '(1 2 3 4 3 2 1))
⇒ (1 2 3 4 3 2 "1")(-replace-last "foo" "bar" '("a" "nice" "foo" "sentence" "about" "foo"))
⇒ ("a" "nice" "foo" "sentence" "about" "bar")(-replace-last 1 2 nil)
⇒ nilFunction: -insert-at (n x list)
Return a list with x inserted into list at position n.
See also: -splice (see -splice), -splice-list (see -splice-list)
(-insert-at 1 'x '(a b c))
⇒ (a x b c)(-insert-at 12 'x '(a b c))
⇒ (a b c x)Function: -replace-at (n x list)
Return a list with element at Nth position in list replaced with x.
See also: -replace (see -replace)
(-replace-at 0 9 '(0 1 2 3 4 5))
⇒ (9 1 2 3 4 5)(-replace-at 1 9 '(0 1 2 3 4 5))
⇒ (0 9 2 3 4 5)(-replace-at 4 9 '(0 1 2 3 4 5))
⇒ (0 1 2 3 9 5)Function: -update-at (n func list)
Use func to update the Nth element of list. Return a copy of list where the Nth element is replaced with the result of calling func on it.
See also: -map-when (see -map-when)
(-update-at 0 (lambda (x) (+ x 9)) '(0 1 2 3 4 5))
⇒ (9 1 2 3 4 5)(-update-at 1 (lambda (x) (+ x 8)) '(0 1 2 3 4 5))
⇒ (0 9 2 3 4 5)(--update-at 2 (length it) '("foo" "bar" "baz" "quux"))
⇒ ("foo" "bar" 3 "quux")Function: -remove-at (n list)
Return list with its element at index n removed. That is, remove any element selected as (nth n list) from list and return the result.
This is a non-destructive operation: parts of list (but not necessarily all of it) are copied as needed to avoid destructively modifying it.
See also: -remove-at-indices (see -remove-at-indices), -remove (see -remove).
(-remove-at 0 '(a b c))
⇒ (b c)(-remove-at 1 '(a b c))
⇒ (a c)(-remove-at 2 '(a b c))
⇒ (a b)Function: -remove-at-indices (indices list)
Return list with its elements at indices removed. That is, for each index i in indices, remove any element selected as (nth i list) from list.
This is a non-destructive operation: parts of list (but not necessarily all of it) are copied as needed to avoid destructively modifying it.
See also: -remove-at (see -remove-at), -remove (see -remove).
(-remove-at-indices '(0) '(a b c d e))
⇒ (b c d e)(-remove-at-indices '(1 3) '(a b c d e))
⇒ (a c e)(-remove-at-indices '(4 0 2) '(a b c d e))
⇒ (b d)