query
On this page

collect

lib.attrsets.collect

Docs pulled from | This Revision | about 3 hours ago


Recursively collect sets that verify a given predicate named pred from the set attrs. The recursion is stopped when the predicate is verified.

Inputs

pred

Given an attribute's value, determine if recursion should stop.

attrs

The attribute set to recursively collect.

Type

collect :: (AttrSet -> Bool) -> AttrSet -> [x]

Examples

lib.attrsets.collect usage example

collect isList { a = { b = ["b"]; }; c = [1]; }
=> [["b"] [1]]

collect (x: x ? outPath)
   { a = { outPath = "a/"; }; b = { outPath = "b/"; }; }
=> [{ outPath = "a/"; } { outPath = "b/"; }]

Noogle detected

Aliases

Implementation

The following is the current implementation of this function.

collect =
    pred:
    attrs:
    if pred attrs then
      [ attrs ]
    else if isAttrs attrs then
      concatMap (collect pred) (attrValues attrs)
    else
      [];