@ -5,7 +5,8 @@ with {
inherit ( import ./trivial.nix ) or ;
inherit ( import ./default.nix ) fold ;
inherit ( import ./strings.nix ) concatStringsSep ;
inherit ( import ./lists.nix ) concatMap concatLists ;
inherit ( import ./lists.nix ) concatMap concatLists all ;
inherit ( import ./misc.nix ) maybeAttr ;
} ;
rec {
@ -78,6 +79,16 @@ rec {
filterAttrs = pred : set :
listToAttrs ( fold ( n : ys : let v = getAttr n set ; in if pred n v then [ ( nameValuePair n v ) ] ++ ys else ys ) [ ] ( attrNames set ) ) ;
/* f o l d A t t r s : a p p l y f o l d f u n c t i o n s t o v a l u e s g r o u p e d b y k e y . E g a c c u m u l a t e v a l u e s a s l i s t :
foldAttrs ( n : a : [ n ] ++ a ) [ ] [ { a = 2 ; } { a = 3 ; } ]
= > { a = [ 2 3 ] ; }
* /
foldAttrs = op : nul : list_of_attrs :
fold ( n : a :
fold ( name : o :
o // ( listToAttrs [ { inherit name ; value = op ( getAttr name n ) ( maybeAttr name nul a ) ; } ] )
) a ( attrNames n )
) { } list_of_attrs ;
/* R e c u r s i v e l y c o l l e c t s e t s t h a t v e r i f y a g i v e n p r e d i c a t e n a m e d ` p r e d '
from the set ` attrs' . The recursion is stopped when the predicate is