[Haskell-cafe] Filter by several predicates at once

Dougal Stanton ithika at gmail.com
Thu Jan 17 09:22:12 EST 2008


Are the functions

> passall, passany :: [a -> Bool] -> a -> Bool
> passall ps v = and $ map ($v) ps
> passany ps v = or $ map ($v) ps

or something similar defined anywhere? Such that one can write

> filter (passany tests) [0..10]
> filter (passall tests) [0..10]

where

> tests = [>5, odd]

Or is there a better way of filtering by several predicates for each
value without using

> filter p3 . filter p2 . filter p1

or

> filter (\v -> p1 v && p2 v && p3 v) vs

Cheers,

D

-- 
Dougal Stanton
dougal at dougalstanton.net // http://www.dougalstanton.net


More information about the Haskell-Cafe mailing list