diff options
author | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2009-09-28 18:22:44 +0000 |
---|---|---|
committer | Nicolas Pierron <nicolas.b.pierron@gmail.com> | 2009-09-28 18:22:44 +0000 |
commit | b3b40ebf791156abba529b2e50678f8958e284c3 (patch) | |
tree | 5d83b10b244c700e9613fc233bab14df072bfb4f /pkgs/lib | |
parent | 7ff2778cc69ef8997d36e5fcb9174f8e65b19b61 (diff) | |
download | nixlib-b3b40ebf791156abba529b2e50678f8958e284c3.tar nixlib-b3b40ebf791156abba529b2e50678f8958e284c3.tar.gz nixlib-b3b40ebf791156abba529b2e50678f8958e284c3.tar.bz2 nixlib-b3b40ebf791156abba529b2e50678f8958e284c3.tar.lz nixlib-b3b40ebf791156abba529b2e50678f8958e284c3.tar.xz nixlib-b3b40ebf791156abba529b2e50678f8958e284c3.tar.zst nixlib-b3b40ebf791156abba529b2e50678f8958e284c3.zip |
Add setAttrByPath:
- used to defined an attribute with its path as a list of attribute names. svn path=/nixpkgs/trunk/; revision=17480
Diffstat (limited to 'pkgs/lib')
-rw-r--r-- | pkgs/lib/attrsets.nix | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 9f911299f1bb..ab3d3f49e180 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -22,6 +22,14 @@ rec { then attrByPath (tail attrPath) default (getAttr attr e) else default; + /* Return nested attribute set in which an attribute is set. For instance + ["x" "y"] applied with some value v returns `x.y = v;' */ + setAttrByPath = attrPath: value: + if attrPath == [] then value + else listToAttrs [( + nameValuePair (head attrPath) (setAttrByPath (tail attrPath) value) + )]; + /* Backwards compatibility hack: lib.attrByPath used to be called lib.getAttr, which was confusing given that there was also a |