filterAttrs
lib.attrsets.filterAttrs
Docs pulled from | This Revision | about 1 hour ago
Filter an attribute set 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
filterAttrs :: (String -> Any -> Bool) -> AttrSet -> AttrSet
Examples
lib.attrsets.filterAttrs
usage example
filterAttrs (n: v: n == "foo") { foo = 1; bar = 2; }
=> { foo = 1; }
Noogle detected
Implementation
The following is the current implementation of this function.
filterAttrs =
pred:
set:
listToAttrs (concatMap (name: let v = set.${name}; in if pred name v then [(nameValuePair name v)] else []) (attrNames set));