Skip to content

Instantly share code, notes, and snippets.

@plaidfinch
Last active August 29, 2015 13:57
Show Gist options
  • Save plaidfinch/9656662 to your computer and use it in GitHub Desktop.
Save plaidfinch/9656662 to your computer and use it in GitHub Desktop.
module MultiFilters where
import Control.Applicative ((<$>))
(.:) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
a .: b = (a .) . b
juxt :: [a -> b] -> a -> [b]
juxt = sequence
juxtReduce :: ([b] -> c) -> [a -> b] -> a -> c
juxtReduce = (.: juxt)
filterAll :: [a -> Bool] -> [a] -> [a]
filterAll = filter . juxtReduce and
filterAny :: [a -> Bool] -> [a] -> [a]
filterAny = filter . juxtReduce or
divisibleBy :: Integral a => a -> a -> Bool
divisibleBy x y = y `mod` x == 0
example = filterAll (not .: divisibleBy <$> [2,3,5]) [1..20]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment