From 5e83e93e97625bdeac8cbeb965b4d60aa2bf2558 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Mar 2013 16:33:01 +0100 Subject: [PATCH] =?UTF-8?q?Add=20a=20library=20function=20=E2=80=98genAttr?= =?UTF-8?q?s=E2=80=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It generates an attribute set by mapping a function over a list of attribute names. --- pkgs/lib/attrsets.nix | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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";