query
On this page

mapAttrsRecursive

lib.attrsets.mapAttrsRecursive



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 argument 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.

Example

mapAttrsRecursive (path: value: concatStringsSep "-" (path ++ [value]))
  { n = { a = "A"; m = { b = "B"; c = "C"; }; }; d = "D"; }
=> { 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

Arguments

  • [f] A function, given a list of attribute names and a value, returns a new value.
  • [set] Set to recursively map over.

Noogle also knows

Aliases