about summary refs log tree commit diff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/default.nix2
-rw-r--r--lib/lists.nix13
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/default.nix b/lib/default.nix
index 3efaaf0f8f9e..f876c57e25c8 100644
--- a/lib/default.nix
+++ b/lib/default.nix
@@ -71,7 +71,7 @@ let
       zipAttrsWithNames zipAttrsWith zipAttrs recursiveUpdateUntil
       recursiveUpdate matchAttrs overrideExisting getOutput getBin
       getLib getDev chooseDevOutputs zipWithNames zip;
-    inherit (lists) singleton foldr fold foldl foldl' imap0 imap1
+    inherit (lists) singleton foreach foldr fold foldl foldl' imap0 imap1
       concatMap flatten remove findSingle findFirst any all count
       optional optionals toList range partition zipListsWith zipLists
       reverseList listDfs toposort sort naturalSort compareLists take
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))`.