mapAttrs'
lib.mapAttrs'
Docs pulled from | This Revision | 16 minutes ago
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
.
Inputs
f
-
A function, given an attribute's name and value, returns a new
nameValuePair
. set
-
Attribute set to map over.
Type
mapAttrs' :: (String -> Any -> { name :: String; value :: Any; }) -> AttrSet -> AttrSet
Examples
lib.attrsets.mapAttrs'
usage example
mapAttrs' (name: value: nameValuePair ("foo_" + name) ("bar-" + value))
{ x = "a"; y = "b"; }
=> { foo_x = "bar-a"; foo_y = "bar-b"; }
Noogle detected
Implementation
The following is the current implementation of this function.
mapAttrs' = f: set: listToAttrs (map (attr: f attr set.${attr}) (attrNames set));