diff options
author | zimbatm <zimbatm@zimbatm.com> | 2017-07-04 23:29:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-04 23:29:23 +0100 |
commit | 4d545297d85c8f32f7ab496d0759f40d881bd61d (patch) | |
tree | c3309bda805bce2028f2fe53b6662bd4a3352936 /lib/lists.nix | |
parent | a0fa61788b930b05afc475b61a9963655e969ef9 (diff) |
lib: introduce imap0, imap1 (#25543)
* lib: introduce imap0, imap1 For historical reasons, imap starts counting at 1 and it's not consistent with the rest of the lib. So for now we split imap into imap0 that starts counting at zero and imap1 that starts counting at 1. And imap is marked as deprecated. See https://github.com/NixOS/nixpkgs/commit/c71e2d42359f9900ea2c290d141c0d606471da16#commitcomment-21873221 * replace uses of lib.imap * lib: move imap to deprecated.nix
Diffstat (limited to 'lib/lists.nix')
-rw-r--r-- | lib/lists.nix | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/lists.nix b/lib/lists.nix index fd746f4f97b1f..a04b1b278935a 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -77,15 +77,21 @@ rec { */ foldl' = builtins.foldl' or foldl; - /* Map with index + /* Map with index starting from 0 - FIXME(zimbatm): why does this start to count at 1? + Example: + imap0 (i: v: "${v}-${toString i}") ["a" "b"] + => [ "a-0" "b-1" ] + */ + imap0 = f: list: genList (n: f n (elemAt list n)) (length list); + + /* Map with index starting from 1 Example: - imap (i: v: "${v}-${toString i}") ["a" "b"] + imap1 (i: v: "${v}-${toString i}") ["a" "b"] => [ "a-1" "b-2" ] */ - imap = f: list: genList (n: f (n + 1) (elemAt list n)) (length list); + imap1 = f: list: genList (n: f (n + 1) (elemAt list n)) (length list); /* Map and concatenate the result. |