Skip to content

Instantly share code, notes, and snippets.

@slimane
Created March 7, 2014 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slimane/9404497 to your computer and use it in GitHub Desktop.
Save slimane/9404497 to your computer and use it in GitHub Desktop.
import Data.List
data Sex = Male | Female deriving (Show, Eq, Ord)
data Customer = Customer{ sex :: Sex, age :: Int } deriving(Show, Eq, Ord)
(|>) :: a -> (a -> b) -> b
x |> f = f x
main = do
let customers = [Customer Female 24,
Customer Male 23,
Customer Female 28,
Customer Female 59,
Customer Female 12,
Customer Female 24,
Customer Female 59,
Customer Male 59
]
putStrLn . show $ customers
|> filter (\c -> sex c == Female)
|> sortBy (\c n -> compare (age c) (age n))
|> groupBy (==)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment