diff options
Diffstat (limited to 'pkgs/lib/lists.nix')
-rw-r--r-- | pkgs/lib/lists.nix | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/pkgs/lib/lists.nix b/pkgs/lib/lists.nix index d1cdf5b68ab1..e5b47f0d9ce7 100644 --- a/pkgs/lib/lists.nix +++ b/pkgs/lib/lists.nix @@ -1,7 +1,7 @@ # General list operations. rec { - inherit (builtins) head tail isList; + inherit (builtins) head tail length isList; # Create a list consisting of a single element. `singleton x' is @@ -27,6 +27,10 @@ rec { then nul else foldl op (op nul (head list)) (tail list); + # map with index: `imap (i: v: "${v}-${toString i}") ["a" "b"] == + # ["a-1" "b-2"]' + imap = f: list: + zipListsWith f (range 1 (length list)) list; # Concatenate a list of lists. concatLists = fold (x: y: x ++ y) []; @@ -136,7 +140,7 @@ rec { zipListsWith = f: fst: snd: if fst != [] && snd != [] then [ (f (head fst) (head snd)) ] - ++ zipLists (tail fst) (tail snd) + ++ zipListsWith f (tail fst) (tail snd) else []; zipLists = zipListsWith (fst: snd: { inherit fst snd; }); |