Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

haskell, chaining filters

Tags:

haskell

filter

to write "map f (map g xs)" as a single call to map you could write

example xs = map (f.g) xs

but how would you write "filter p (filter q xs)" as a single call to filter? the dot operator doesnt seem to work for filter as it does for maps. guessing you'd use something else for predicates?

like image 709
derp Avatar asked Nov 10 '09 23:11

derp


1 Answers

If you defined a function both that looked like this:

both :: (a -> Bool) -> (a -> Bool) -> a -> Bool
both f g x = f x && g x

Then you could write:

example xs = filter (both p q) xs

I'm not sure if there's a standard function that does this for you...

like image 131
Paige Ruten Avatar answered Sep 21 '22 18:09

Paige Ruten