From 5e83e93e97625bdeac8cbeb965b4d60aa2bf2558 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 6 Mar 2013 16:33:01 +0100 Subject: Add a library function ‘genAttrs’ 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(-) (limited to 'pkgs/lib') 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"; -- cgit 1.4.1