about summary refs log tree commit diff
path: root/lib/lists.nix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lists.nix')
-rw-r--r--lib/lists.nix13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/lists.nix b/lib/lists.nix
index 30d87ece6641..f9953720ee10 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))`.