From 4b5c1dec62395a662665067f14894bd64ba6de0f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 14 Jun 2012 19:07:01 +0000 Subject: [PATCH] =?UTF-8?q?*=20Add=20a=20function=20=E2=80=98mapAttrsToLis?= =?UTF-8?q?t=E2=80=99=20that=20maps=20a=20function=20over=20the=20=20=20at?= =?UTF-8?q?tributes=20in=20a=20set,=20returning=20a=20list.=20=20(Note=20t?= =?UTF-8?q?hat=20the=20regular=20=20=20=E2=80=98mapAttrs=E2=80=99=20return?= =?UTF-8?q?s=20an=20attribute=20set.)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit svn path=/nixpkgs/trunk/; revision=34509 --- pkgs/lib/attrsets.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkgs/lib/attrsets.nix b/pkgs/lib/attrsets.nix index 260c61558a4..5e4e9df3711 100644 --- a/pkgs/lib/attrsets.nix +++ b/pkgs/lib/attrsets.nix @@ -146,6 +146,18 @@ rec { listToAttrs (map (attr: f attr (getAttr attr set)) (attrNames set)); + /* Call a function for each attribute in the given set and return + the result in a list. + + Example: + mapAttrsToList (name: value: name + value) + { x = "a"; y = "b"; } + => [ "xa" "yb" ] + */ + mapAttrsToList = f: attrs: + map (name: f name (getAttr name attrs)) (attrNames attrs); + + /* Like `mapAttrs', except that it recursively applies itself to attribute sets. Also, the first argument of the argument function is a *list* of the names of the containing attributes.