3
0
Fork 0
forked from mirrors/nixpkgs

Add a library function ‘genAttrs’

It generates an attribute set by mapping a function over a list of
attribute names.
This commit is contained in:
Eelco Dolstra 2013-03-06 16:33:01 +01:00
parent 00de01f58b
commit 5e83e93e97

View file

@ -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";