diff options
author | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-03-06 16:33:01 +0100 |
---|---|---|
committer | Eelco Dolstra <eelco.dolstra@logicblox.com> | 2013-03-06 16:33:01 +0100 |
commit | 5e83e93e97625bdeac8cbeb965b4d60aa2bf2558 (patch) | |
tree | d6d86896aa4e02acb93a5026c88d9bce1fb2dae4 /pkgs/lib | |
parent | 00de01f58b4e278358a264d252f3cac69575dfd4 (diff) | |
download | nixlib-5e83e93e97625bdeac8cbeb965b4d60aa2bf2558.tar nixlib-5e83e93e97625bdeac8cbeb965b4d60aa2bf2558.tar.gz nixlib-5e83e93e97625bdeac8cbeb965b4d60aa2bf2558.tar.bz2 nixlib-5e83e93e97625bdeac8cbeb965b4d60aa2bf2558.tar.lz nixlib-5e83e93e97625bdeac8cbeb965b4d60aa2bf2558.tar.xz nixlib-5e83e93e97625bdeac8cbeb965b4d60aa2bf2558.tar.zst nixlib-5e83e93e97625bdeac8cbeb965b4d60aa2bf2558.zip |
Add a library function ‘genAttrs’
It generates an attribute set by mapping a function over a list of attribute names.
Diffstat (limited to 'pkgs/lib')
-rw-r--r-- | pkgs/lib/attrsets.nix | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index fcdc3c31f290..f562a2f7df40 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -194,7 +194,7 @@ rec { (as: !(as ? "type" && as.type == "derivation")) (x: ... do something ...) attrs - */ + */ mapAttrsRecursiveCond = cond: f: set: let recurse = path: set: @@ -208,6 +208,17 @@ rec { in recurse [] set; + /* Generate an attribute set by mapping a function over a list of + attribute names. + + Example: + genAttrs [ "foo" "bar" ] (name: "x_" + name) + => { foo = "x_foo"; bar = "x_bar"; } + */ + genAttrs = names: f: + listToAttrs (map (n: nameValuePair n (f n)) names); + + /* Check whether the argument is a derivation. */ isDerivation = x: isAttrs x && x ? type && x.type == "derivation"; |