summary refs log tree commit diff
path: root/lib/attrsets.nix
diff options
context:
space:
mode:
authorJohn Ericson <Ericson2314@Yahoo.com>2017-04-01 15:34:38 -0400
committerJohn Ericson <Ericson2314@Yahoo.com>2017-04-17 17:13:01 -0400
commitfffcee35f9b2042d4edc5dccb3379972e03ffd84 (patch)
tree2e8c2fb8599d0fb46b57a727a3d33e3c51d9bc49 /lib/attrsets.nix
parent22277893923cdf26004d83b608b7e1c3ca7030fb (diff)
downloadnixpkgs-fffcee35f9b2042d4edc5dccb3379972e03ffd84.tar
nixpkgs-fffcee35f9b2042d4edc5dccb3379972e03ffd84.tar.gz
nixpkgs-fffcee35f9b2042d4edc5dccb3379972e03ffd84.tar.bz2
nixpkgs-fffcee35f9b2042d4edc5dccb3379972e03ffd84.tar.lz
nixpkgs-fffcee35f9b2042d4edc5dccb3379972e03ffd84.tar.xz
nixpkgs-fffcee35f9b2042d4edc5dccb3379972e03ffd84.tar.zst
nixpkgs-fffcee35f9b2042d4edc5dccb3379972e03ffd84.zip
lib: Fix `matchAttrs`
Diffstat (limited to 'lib/attrsets.nix')
-rw-r--r--lib/attrsets.nix13
1 files changed, 5 insertions, 8 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix
index f9e6b7495fc..c686e1d20eb 100644
--- a/lib/attrsets.nix
+++ b/lib/attrsets.nix
@@ -2,7 +2,7 @@
 
 let
   inherit (builtins) head tail length;
-  inherit (import ./trivial.nix) or;
+  inherit (import ./trivial.nix) and or;
   inherit (import ./default.nix) fold;
   inherit (import ./strings.nix) concatStringsSep;
   inherit (import ./lists.nix) concatMap concatLists all deepSeqList;
@@ -417,18 +417,15 @@ rec {
 
   /* Returns true if the pattern is contained in the set. False otherwise.
 
-     FIXME(zimbatm): this example doesn't work !!!
-
      Example:
-       sys = mkSystem { }
-       matchAttrs { cpu = { bits = 64; }; } sys
+       matchAttrs { cpu = {}; } { cpu = { bits = 64; }; }
        => true
    */
-  matchAttrs = pattern: attrs:
-    fold or false (attrValues (zipAttrsWithNames (attrNames pattern) (n: values:
+  matchAttrs = pattern: attrs: assert isAttrs pattern;
+    fold and true (attrValues (zipAttrsWithNames (attrNames pattern) (n: values:
       let pat = head values; val = head (tail values); in
       if length values == 1 then false
-      else if isAttrs pat then isAttrs val && matchAttrs head values
+      else if isAttrs pat then isAttrs val && matchAttrs pat val
       else pat == val
     ) [pattern attrs]));