summary refs log tree commit diff
path: root/pkgs/lib/attrsets.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-03-07 19:33:52 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-03-07 19:33:52 +0100
commit674c51af3c0f3f1c65e1975893fdf6438bc57f28 (patch)
tree3020861cf515bc567e191361357d42e11ac817ee /pkgs/lib/attrsets.nix
parentda437144fa4f446e91b5f7f78b55faa4d12de58a (diff)
parentd742d26b0d8c7125fb29417fcb40e2665e10100d (diff)
downloadnixlib-674c51af3c0f3f1c65e1975893fdf6438bc57f28.tar
nixlib-674c51af3c0f3f1c65e1975893fdf6438bc57f28.tar.gz
nixlib-674c51af3c0f3f1c65e1975893fdf6438bc57f28.tar.bz2
nixlib-674c51af3c0f3f1c65e1975893fdf6438bc57f28.tar.lz
nixlib-674c51af3c0f3f1c65e1975893fdf6438bc57f28.tar.xz
nixlib-674c51af3c0f3f1c65e1975893fdf6438bc57f28.tar.zst
nixlib-674c51af3c0f3f1c65e1975893fdf6438bc57f28.zip
Merge remote-tracking branch 'origin/master' into stdenv-updates
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";