* Split lib/default.nix into several files, as it had become a big
mess. Also cleaned up some functions:
- foldl appeared broken (it recursively called fold).
- Renamed logicalAND/logicalOR to and/or.
- Removed listOfListsToAttrs, eqStrings: obsolete.
- Removed isInList, which does the same thing as elem.
- stringToCharacters: don't return a "" at the end of the list.
- Renamed concatList to concat, as concatList (singular) is a
misnomer: it takes two lists. Likewise, renamed mergeAttr to
mergeAttrs.
misc.nix still contains a lot of stuff that should be refactored and
moved to other files.
svn path=/nixpkgs/trunk/; revision=14013
This commit is contained in:
22
pkgs/lib/attrsets.nix
Normal file
22
pkgs/lib/attrsets.nix
Normal file
@@ -0,0 +1,22 @@
|
||||
# Operations on attribute sets.
|
||||
|
||||
with { inherit (builtins) head tail; };
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user