filterAttrsRecursive
lib.attrsets.filterAttrsRecursive
Docs pulled from | This Revision | about 1 hour 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
trueto include the attribute, orfalseto 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)
);