2013-01-09 10:07:46 +00:00
|
|
|
|
|
|
|
data Either a b = Left a | Right b
|
|
|
|
|
2013-02-07 18:54:21 +00:00
|
|
|
either : (a -> c) -> (b -> c) -> Either a b -> c
|
2013-01-09 10:07:46 +00:00
|
|
|
either f g e = case e of { Left x -> f x ; Right y -> g y }
|
|
|
|
|
2013-02-07 18:54:21 +00:00
|
|
|
|
|
|
|
isLeft : Either a b -> Bool
|
2013-01-09 10:07:46 +00:00
|
|
|
isLeft e = case e of { Left _ -> True ; _ -> False }
|
2013-02-07 18:54:21 +00:00
|
|
|
|
|
|
|
isRight : Either a b -> Bool
|
2013-01-09 10:07:46 +00:00
|
|
|
isRight e = case e of { Right _ -> True ; _ -> False }
|
|
|
|
|
2013-02-07 18:54:21 +00:00
|
|
|
|
|
|
|
lefts : [Either a b] -> [a]
|
2013-01-09 10:07:46 +00:00
|
|
|
lefts = Elm.List.filter isLeft
|
2013-02-07 18:54:21 +00:00
|
|
|
|
|
|
|
rights : [Either a b] -> [b]
|
2013-01-09 10:07:46 +00:00
|
|
|
rights = Elm.List.filter isRight
|
|
|
|
|
2013-02-07 18:54:21 +00:00
|
|
|
partition : [Either a b] -> ([a],[b])
|
2013-01-09 10:07:46 +00:00
|
|
|
partition = Elm.List.partition isLeft
|