mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-01-21 20:34:06 +00:00
lists: Add imap function to iterate over a list with the index of each
element. svn path=/nixpkgs/trunk/; revision=27013
This commit is contained in:
parent
781770eaa9
commit
85d3fd3e3c
@ -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) [];
|
||||
|
Loading…
Reference in New Issue
Block a user