mapAttrsRecursive
lib.mapAttrsRecursive
Docs pulled from | This Revision | 18 minutes ago
Nixpkgs manual
Like mapAttrs, except that it recursively applies itself to the leaf attributes of a potentially-nested attribute set:
the second argument of the function will never be an attrset.
Also, the first argument of the mapping function is a list of the attribute names that form the path to the leaf attribute.
For a function that gives you control over what counts as a leaf, see mapAttrsRecursiveCond.
Map over leaf attributes
mapAttrsRecursive (path: value: concatStringsSep "-" (path ++ [value]))
{ n = { a = "A"; m = { b = "B"; c = "C"; }; }; d = "D"; }
evaluates to
{ n = { a = "n-a-A"; m = { b = "n-m-b-B"; c = "n-m-c-C"; }; }; d = "d-D"; }
Type
mapAttrsRecursive :: ([String] -> a -> b) -> AttrSet -> AttrSet
Noogle detected
Implementation
The following is the current implementation of this function.
f: set:
let
recurse =
path:
mapAttrs (
name: value:
if isAttrs value && cond value then recurse (path ++ [ name ]) value else f (path ++ [ name ]) value
);
in
recurse [ ] set