mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2024-12-26 12:53:59 +03:00
lib: Fix matchAttrs
This commit is contained in:
parent
2227789392
commit
fffcee35f9
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
let
|
let
|
||||||
inherit (builtins) head tail length;
|
inherit (builtins) head tail length;
|
||||||
inherit (import ./trivial.nix) or;
|
inherit (import ./trivial.nix) and or;
|
||||||
inherit (import ./default.nix) fold;
|
inherit (import ./default.nix) fold;
|
||||||
inherit (import ./strings.nix) concatStringsSep;
|
inherit (import ./strings.nix) concatStringsSep;
|
||||||
inherit (import ./lists.nix) concatMap concatLists all deepSeqList;
|
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.
|
/* Returns true if the pattern is contained in the set. False otherwise.
|
||||||
|
|
||||||
FIXME(zimbatm): this example doesn't work !!!
|
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
sys = mkSystem { }
|
matchAttrs { cpu = {}; } { cpu = { bits = 64; }; }
|
||||||
matchAttrs { cpu = { bits = 64; }; } sys
|
|
||||||
=> true
|
=> true
|
||||||
*/
|
*/
|
||||||
matchAttrs = pattern: attrs:
|
matchAttrs = pattern: attrs: assert isAttrs pattern;
|
||||||
fold or false (attrValues (zipAttrsWithNames (attrNames pattern) (n: values:
|
fold and true (attrValues (zipAttrsWithNames (attrNames pattern) (n: values:
|
||||||
let pat = head values; val = head (tail values); in
|
let pat = head values; val = head (tail values); in
|
||||||
if length values == 1 then false
|
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
|
else pat == val
|
||||||
) [pattern attrs]));
|
) [pattern attrs]));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user