diff options
Diffstat (limited to 'lib/lists.nix')
-rw-r--r-- | lib/lists.nix | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/lists.nix b/lib/lists.nix index 30d87ece66412..e4fcf959b60c8 100644 --- a/lib/lists.nix +++ b/lib/lists.nix @@ -21,6 +21,19 @@ rec { */ singleton = x: [x]; + /* Apply the function to each element in the list. Same as `map`, but arguments + flipped. + + Type: forEach :: [a] -> (a -> b) -> [b] + + Example: + forEach [ 1 2 ] (x: + toString x + ) + => [ "1" "2" ] + */ + forEach = xs: f: map f xs; + /* “right fold” a binary function `op` between successive elements of `list` with `nul' as the starting value, i.e., `foldr op nul [x_1 x_2 ... x_n] == op x_1 (op x_2 ... (op x_n nul))`. |