query
On this page

foldAttrs

lib.attrsets.foldAttrs

Docs pulled from | This Revision | about 2 hours 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 ]; }

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;