Author: eelco
Date: Fri May 25 17:01:58 2012
New Revision: 34246
URL: https://nixos.org/websvn/nix/?rev=34246&sc=1
Log:
* Add a variant of mapAttrs that allows rewriting the name of each
attribute in addition to the value.
Modified:
nixpkgs/trunk/pkgs/lib/attrsets.nix
Modified: nixpkgs/trunk/pkgs/lib/attrsets.nix
==============================================================================
--- nixpkgs/trunk/pkgs/lib/attrsets.nix Fri May 25 16:19:52 2012 (r34245)
+++ nixpkgs/trunk/pkgs/lib/attrsets.nix Fri May 25 17:01:58 2012 (r34246)
@@ -126,12 +126,25 @@
Example:
mapAttrs (name: value: name + "-" + value)
- {x = "foo"; y = "bar";}
- => {x = "x-foo"; y = "y-bar";}
+ { x = "foo"; y = "bar"; }
+ => { x = "x-foo"; y = "y-bar"; }
*/
mapAttrs = f: set:
listToAttrs (map (attr: nameValuePair attr (f attr (getAttr attr set)))
(attrNames set));
-
+
+
+ /* Like `mapAttrs', but allows the name of each attribute to be
+ changed in addition to the value. The applied function should
+ return both the new name and value as a `nameValuePair'.
+
+ Example:
+ mapAttrs' (name: value: nameValuePair ("foo_" + name) ("bar-" + value))
+ { x = "a"; y = "b"; }
+ => { foo_x = "bar-a"; foo_y = "bar-b"; }
+ */
+ mapAttrs' = f: set:
+ listToAttrs (map (attr: f attr (getAttr attr set)) (attrNames set));
+
/* Like `mapAttrs', except that it recursively applies itself to
attribute sets. Also, the first argument of the argument
_______________________________________________
nix-commits mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-commits