Skip to content

Instantly share code, notes, and snippets.

@axelGschaider
Created August 26, 2012 17:14
Show Gist options
  • Save axelGschaider/3481734 to your computer and use it in GitHub Desktop.
Save axelGschaider/3481734 to your computer and use it in GitHub Desktop.
hCombiner
import Data.Monoid
--This is sparta! Filter the 500!
sparta :: (Integer -> Bool) -> [Integer]
sparta = flip filter [1 .. 500]
-- now the question is: how can multiple clauses for the same Integer be combined?
(<&&>) :: (a -> Bool) -> (a -> Bool) -> (a -> Bool)
f <&&> g = \x -> f x && g x
(<||>) :: (a -> Bool) -> (a -> Bool) -> a -> Bool
f <||> g = \x -> f x || g x
--try
nobodyLives = sparta $ odd <&&> even
everybodyLives = sparta $ odd <||> even
someLive = sparta $ odd <&&> (<100) <||> (>400)
-- nice. A bit more generic?
(<++>) :: (Monoid m) => (a -> m) -> (a -> m) -> a -> m
f <++> g = \x -> (f x) `mappend` (g x)
-- but there has got to be something more that I'm missing right?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment