mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-28 09:53:10 +00:00
5ddfa7ed64
svn path=/nixpkgs/trunk/; revision=14425
34 lines
1.0 KiB
Nix
34 lines
1.0 KiB
Nix
# Operations on attribute sets.
|
|
|
|
with {
|
|
inherit (builtins) head tail;
|
|
inherit (import ./default.nix) fold;
|
|
};
|
|
|
|
rec {
|
|
inherit (builtins) attrNames listToAttrs hasAttr isAttrs;
|
|
|
|
|
|
# Return an attribute from nested attribute sets. For instance ["x"
|
|
# "y"] applied to some set e returns e.x.y, if it exists. The
|
|
# default value is returned otherwise. !!! there is also
|
|
# builtins.getAttr (is there a better name for this function?)
|
|
getAttr = attrPath: default: e:
|
|
let attr = head attrPath;
|
|
in
|
|
if attrPath == [] then e
|
|
else if builtins ? hasAttr && hasAttr attr e
|
|
then getAttr (tail attrPath) default (builtins.getAttr attr e)
|
|
else default;
|
|
|
|
# ordered by name
|
|
attrValues = attrs: attrVals (__attrNames attrs) attrs;
|
|
|
|
attrVals = nameList : attrSet :
|
|
map (x: builtins.getAttr x attrSet) nameList;
|
|
|
|
# iterates over a list of attributes collecting the attribute attr if it exists
|
|
catAttrs = attr : l : fold ( s : l : if (hasAttr attr s) then [(builtins.getAttr attr s)] ++ l else l) [] l;
|
|
|
|
|
|
} |