···
+
inherit (builtins) head tail length isList elemAt concatLists filter elem genList;
# Create a list consisting of a single element. `singleton x' is
···
foldl' = builtins.foldl' or foldl;
+
# Map with index: `imap (i: v: "${v}-${toString i}") ["a" "b"] ==
+
# ["a-1" "b-2"]'. FIXME: why does this start to count at 1?
+
if builtins ? genList then
+
f: list: genList (n: f (n + 1) (elemAt list n)) (length list)
+
else [ (f (n + 1) (elemAt list n)) ] ++ imap' (n + 1);
# Map and concatenate the result.
···
# Return a list of integers from `first' up to and including `last'.
+
if builtins ? genList then
+
else genList (n: first + n) (last - first + 1)
+
else [first] ++ range (first + 1) last;
# Partition the elements of a list in two lists, `right' and
···
) { right = []; wrong = []; };
+
if builtins ? genList then
+
f: fst: snd: genList (n: f (elemAt fst n) (elemAt snd n)) (min (length fst) (length snd))
+
len = min (length fst) (length snd);
+
[ (f (elemAt fst n) (elemAt snd n)) ]
+
++ zipListsWith' (n + 1)
zipLists = zipListsWith (fst: snd: { inherit fst snd; });
+
# Reverse the order of the elements of a list.
+
if builtins ? genList then
+
xs: let l = length xs; in genList (n: elemAt xs (l - n - 1)) l
+
fold (e: acc: acc ++ [ e ]) [];
# Sort a list based on a comparator function which compares two
···
# Return the first (at most) N elements of a list.
+
if builtins ? genList then
+
if n == len || n == count
+
[ (elemAt list n) ] ++ take' (n + 1);
# Remove the first (at most) N elements of a list.
+
if builtins ? genList then
+
count: list: sublist count (length list) list
+
if n == -1 || n < count
+
drop' (n - 1) ++ [ (elemAt list n) ];
+
# Return a list consisting of at most ‘count’ elements of ‘list’,
+
# starting at index ‘start’.
+
sublist = start: count: list:
+
let len = length list; in
+
(n: elemAt list (n + start))
+
(if start >= len then 0
+
else if start + count > len then len - start
# Return the last element of a list.
···
deepSeqList = xs: y: if any (x: deepSeq x false) xs then y else y;
crossLists = f: foldl (fs: args: concatMap (f: map f args) fs) [f];
+
# Remove duplicate elements from the list. O(n^2) complexity.
···
xs = unique (drop 1 list);
+
# Intersects list 'e' and another list. O(nm) complexity.
intersectLists = e: filter (x: elem x e);
+
# Subtracts list 'e' from another list. O(nm) complexity.
subtractLists = e: filter (x: !(elem x e));