getAttr can call builtins.getAttr
svn path=/nixpkgs/trunk/; revision=15694
This commit is contained in:
parent
3157bb1098
commit
ed69e9ed94
@ -1,7 +1,7 @@
|
|||||||
# Operations on attribute sets.
|
# Operations on attribute sets.
|
||||||
|
|
||||||
with {
|
with {
|
||||||
inherit (builtins) head tail;
|
inherit (builtins) head tail isString;
|
||||||
inherit (import ./default.nix) fold;
|
inherit (import ./default.nix) fold;
|
||||||
inherit (import ./strings.nix) concatStringsSep;
|
inherit (import ./strings.nix) concatStringsSep;
|
||||||
};
|
};
|
||||||
@ -18,13 +18,16 @@ rec {
|
|||||||
in
|
in
|
||||||
if attrPath == [] then e
|
if attrPath == [] then e
|
||||||
else if builtins ? hasAttr && hasAttr attr e
|
else if builtins ? hasAttr && hasAttr attr e
|
||||||
then attrByPath (tail attrPath) default (builtins.getAttr attr e)
|
then attrByPath (tail attrPath) default (getAttr attr e)
|
||||||
else default;
|
else default;
|
||||||
|
|
||||||
# keep compatibility for some time. will be removed soon (the name getAttr
|
# keep compatibility for some time. will be removed soon (the name getAttr
|
||||||
# should only be used for the builtins primop)
|
# should only be used for the builtins primop)
|
||||||
getAttr = a : b : c : builtins.trace "depreceated usage of lib.getAttr!"
|
getAttr = a : b : if isString a
|
||||||
(attrByPath a b c);
|
then
|
||||||
|
# should have been called from builtins scope. Don't mind. use builtin function
|
||||||
|
builtins.getAttr a b
|
||||||
|
else c : builtins.trace "depreceated usage of lib.getAttr!" (attrByPath a b c);
|
||||||
|
|
||||||
|
|
||||||
getAttrFromPath = attrPath: set:
|
getAttrFromPath = attrPath: set:
|
||||||
@ -39,7 +42,7 @@ rec {
|
|||||||
=> [as.a as.b as.c]
|
=> [as.a as.b as.c]
|
||||||
*/
|
*/
|
||||||
attrVals = nameList: set:
|
attrVals = nameList: set:
|
||||||
map (x: builtins.getAttr x set) nameList;
|
map (x: getAttr x set) nameList;
|
||||||
|
|
||||||
|
|
||||||
/* Return the values of all attributes in the given set, sorted by
|
/* Return the values of all attributes in the given set, sorted by
|
||||||
@ -59,7 +62,7 @@ rec {
|
|||||||
catAttrs "a" [{a = 1;} {b = 0;} {a = 2;}]
|
catAttrs "a" [{a = 1;} {b = 0;} {a = 2;}]
|
||||||
=> [1 2]
|
=> [1 2]
|
||||||
*/
|
*/
|
||||||
catAttrs = attr: l: fold (s: l: if hasAttr attr s then [(builtins.getAttr attr s)] ++ l else l) [] l;
|
catAttrs = attr: l: fold (s: l: if hasAttr attr s then [(getAttr attr s)] ++ l else l) [] l;
|
||||||
|
|
||||||
|
|
||||||
/* Utility function that creates a {name, value} pair as expected by
|
/* Utility function that creates a {name, value} pair as expected by
|
||||||
@ -78,7 +81,7 @@ rec {
|
|||||||
=> {x = "x-foo"; y = "y-bar";}
|
=> {x = "x-foo"; y = "y-bar";}
|
||||||
*/
|
*/
|
||||||
mapAttrs = f: set:
|
mapAttrs = f: set:
|
||||||
listToAttrs (map (attr: nameValuePair attr (f attr (builtins.getAttr attr set))) (attrNames set));
|
listToAttrs (map (attr: nameValuePair attr (f attr (getAttr attr set))) (attrNames set));
|
||||||
|
|
||||||
|
|
||||||
/* Like `mapAttrs', except that it recursively applies itself to
|
/* Like `mapAttrs', except that it recursively applies itself to
|
||||||
|
Loading…
Reference in New Issue
Block a user