summary refs log tree commit diff
path: root/pkgs/lib
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-13 11:55:45 -0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-13 15:15:16 -0400
commit431c55cbf1f99748cb28566a33d15fb22bf76fe6 (patch)
treea3abc4445c0e7c780870afaf0380d01b58a8137c /pkgs/lib
parent3bf4437622237e5c5c2d23358b0dcfe0839222e6 (diff)
downloadnixlib-431c55cbf1f99748cb28566a33d15fb22bf76fe6.tar
nixlib-431c55cbf1f99748cb28566a33d15fb22bf76fe6.tar.gz
nixlib-431c55cbf1f99748cb28566a33d15fb22bf76fe6.tar.bz2
nixlib-431c55cbf1f99748cb28566a33d15fb22bf76fe6.tar.lz
nixlib-431c55cbf1f99748cb28566a33d15fb22bf76fe6.tar.xz
nixlib-431c55cbf1f99748cb28566a33d15fb22bf76fe6.tar.zst
nixlib-431c55cbf1f99748cb28566a33d15fb22bf76fe6.zip
Use builtin filter, elem, concatLists functions if available
Diffstat (limited to 'pkgs/lib')
-rw-r--r--pkgs/lib/attrsets.nix4
-rw-r--r--pkgs/lib/lists.nix18
2 files changed, 13 insertions, 9 deletions
diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix
index 8d1521812f9b..982f23230c94 100644
--- a/pkgs/lib/attrsets.nix
+++ b/pkgs/lib/attrsets.nix
@@ -5,7 +5,7 @@ with {
   inherit (import ./trivial.nix) or;
   inherit (import ./default.nix) fold;
   inherit (import ./strings.nix) concatStringsSep;
-  inherit (import ./lists.nix) concatMap;
+  inherit (import ./lists.nix) concatMap concatLists;
   inherit (import ./misc.nix) eqStrict;
 };
 
@@ -66,7 +66,7 @@ rec {
        catAttrs "a" [{a = 1;} {b = 0;} {a = 2;}]
        => [1 2]
   */
-  catAttrs = attr: l: fold (s: l: if hasAttr attr s then [(getAttr attr s)] ++ l else l) [] l;
+  catAttrs = attr: l: concatLists (map (s: if hasAttr attr s then [(getAttr attr s)] else []) l);
 
 
   /* Filter an attribute set by removing all attributes for which the
diff --git a/pkgs/lib/lists.nix b/pkgs/lib/lists.nix
index 67b0add50dcb..dcb89aeec141 100644
--- a/pkgs/lib/lists.nix
+++ b/pkgs/lib/lists.nix
@@ -35,7 +35,7 @@ rec {
 
     
   # Concatenate a list of lists.
-  concatLists = fold (x: y: x ++ y) [];
+  concatLists = builtins.concatLists or (fold (x: y: x ++ y) []);
 
 
   # Map and concatenate the result.
@@ -53,20 +53,24 @@ rec {
     
   # Filter a list using a predicate; that is, return a list containing
   # every element from `list' for which `pred' returns true.
-  filter = pred: list:
-    fold (x: y: if pred x then [x] ++ y else y) [] list;
+  filter =
+    builtins.filter or
+    (pred: list:
+      fold (x: y: if pred x then [x] ++ y else y) [] list);
 
     
-  # Remove elements 'e' from a list. Useful for buildInputs
+  # Remove elements equal to 'e' from a list.  Useful for buildInputs.
   remove = e: filter (x: x != e);
 
   
   # Given two lists, removes all elements of the first list from the second list
   removeList = l: filter (x: elem x l);
 
-  
-  # Return true if `list' has an element `x':
-  elem = x: list: fold (a: bs: x == a || bs) false list;
+
+  # Return true if `list' has an element `x'.
+  elem =
+    builtins.elem or
+    (x: list: fold (a: bs: x == a || bs) false list);
 
 
   # Find the sole element in the list matching the specified