filterAttrsRecursive
lib.filterAttrsRecursive
Docs pulled from | This Revision | 10 minutes ago
Filter an attribute set recursively by removing all attributes for which the given predicate return false.
Inputs
pred
-
Predicate taking an attribute name and an attribute value, which returns
true
to include the attribute, orfalse
to exclude the attribute. set
-
The attribute set to filter
Type
filterAttrsRecursive :: (String -> Any -> Bool) -> AttrSet -> AttrSet
Examples
lib.attrsets.filterAttrsRecursive
usage example
filterAttrsRecursive (n: v: v != null) { foo = { bar = null; }; }
=> { foo = {}; }
Noogle detected
Implementation
The following is the current implementation of this function.
filterAttrsRecursive =
pred: set:
listToAttrs (
concatMap (
name:
let
v = set.${name};
in
if pred name v then
[
(nameValuePair name (if isAttrs v then filterAttrsRecursive pred v else v))
]
else
[ ]
) (attrNames set)
);