summary refs log tree commit diff
path: root/lib/lists.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-23 17:19:21 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2015-07-23 18:31:54 +0200
commit637e35deb99c5efbb8bd760a3ad08d3899534ead (patch)
treeea625d5e0795b8a5ea7426745c32b363299a2378 /lib/lists.nix
parentf92619f6b88d10815c56b97238ed7e1f4220c1f9 (diff)
downloadnixlib-637e35deb99c5efbb8bd760a3ad08d3899534ead.tar
nixlib-637e35deb99c5efbb8bd760a3ad08d3899534ead.tar.gz
nixlib-637e35deb99c5efbb8bd760a3ad08d3899534ead.tar.bz2
nixlib-637e35deb99c5efbb8bd760a3ad08d3899534ead.tar.lz
nixlib-637e35deb99c5efbb8bd760a3ad08d3899534ead.tar.xz
nixlib-637e35deb99c5efbb8bd760a3ad08d3899534ead.tar.zst
nixlib-637e35deb99c5efbb8bd760a3ad08d3899534ead.zip
Use foldl' instead of fold in some places
Diffstat (limited to 'lib/lists.nix')
-rw-r--r--lib/lists.nix8
1 files changed, 6 insertions, 2 deletions
diff --git a/lib/lists.nix b/lib/lists.nix
index fa8cbddfd943..9cb164aaade4 100644
--- a/lib/lists.nix
+++ b/lib/lists.nix
@@ -38,6 +38,10 @@ rec {
     in foldl' (length list - 1);
 
 
+  # Strict version of foldl.
+  foldl' = builtins.foldl' or foldl;
+
+
   # map with index: `imap (i: v: "${v}-${toString i}") ["a" "b"] ==
   # ["a-1" "b-2"]'
   imap = f: list:
@@ -59,7 +63,7 @@ rec {
   # == [1 2 3 4 5]' and `flatten 1 == [1]'.
   flatten = x:
     if isList x
-    then fold (x: y: (flatten x) ++ y) [] x
+    then foldl' (x: y: x ++ (flatten y)) [] x
     else [x];
 
 
@@ -96,7 +100,7 @@ rec {
 
   # Count how many times function `pred' returns true for the elements
   # of `list'.
-  count = pred: fold (x: c: if pred x then c + 1 else c) 0;
+  count = pred: foldl' (c: x: if pred x then c + 1 else c) 0;
 
 
   # Return a singleton list or an empty list, depending on a boolean