query
On this page

foldAttrs

lib.foldAttrs

Docs pulled from | This Revision | 10 minutes ago


Apply fold functions to values grouped by key.

Inputs

op

A function, given a value and a collector combines the two.

nul

The starting value.

list_of_attrs

A list of attribute sets to fold together by key.

Type

foldAttrs :: (Any -> Any -> Any) -> Any -> [AttrSets] -> Any

Examples

lib.attrsets.foldAttrs usage example

foldAttrs (item: acc: [item] ++ acc) [] [{ a = 2; } { a = 3; }]
=> { a = [ 2 3 ]; }
(lib.attrsets.foldAttrs)

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

foldAttrs =
    op: nul: list_of_attrs:
    foldr (
      n: a: foldr (name: o: o // { ${name} = op n.${name} (a.${name} or nul); }) a (attrNames n)
    ) { } list_of_attrs;