summary refs log tree commit diff
path: root/pkgs/lib/attrsets.nix
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/lib/attrsets.nix')
-rw-r--r--pkgs/lib/attrsets.nix13
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";