From: ralf Date: Thu, 5 Jun 2003 13:42:51 +0000 (+0000) Subject: [project @ 2003-06-05 13:42:51 by ralf] X-Git-Tag: nhc98-1-18-release~618 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=9da490d9ac1518cce638ab30f758a717b4b7a222;p=haskell-directory.git [project @ 2003-06-05 13:42:51 by ralf] Add listify; other minor revisions. --- diff --git a/Data/Generics.hs b/Data/Generics.hs index 0f79a34..4132aa2 100644 --- a/Data/Generics.hs +++ b/Data/Generics.hs @@ -51,6 +51,7 @@ module Data.Generics ( everywhereM, somewhere, everything, + listify, something, synthesize, @@ -509,7 +510,13 @@ everything :: (r -> r -> r) -> GenericQ r -> GenericQ r -- use ordinary foldl to reduce list of intermediate results -- everything k f x - = foldl k (f x) (gmapQ (everything k f) x) + = foldl k (f x) (gmapQ (everything k f) x) + + +-- | Get a list of all entities that meet a predicate +listify :: Typeable r => (r -> Bool) -> GenericQ [r] +listify p + = everything (++) ([] `mkQ` (\x -> if p x then [x] else [])) -- | Look up a subterm by means of a maybe-typed filter