From 4d545297d85c8f32f7ab496d0759f40d881bd61d Mon Sep 17 00:00:00 2001 From: zimbatm Date: Tue, 4 Jul 2017 23:29:23 +0100 Subject: 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 --- lib/lists.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/lists.nix') 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. -- cgit 1.4.1