elm/libraries/Either.elm

26 lines
561 B
Elm
Raw Normal View History

2013-03-10 08:54:37 +00:00
module Either where
import List
2013-03-10 08:54:37 +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
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
isLeft e = case e of { Left _ -> True ; _ -> False }
2013-02-07 18:54:21 +00:00
isRight : Either a b -> Bool
isRight e = case e of { Right _ -> True ; _ -> False }
2013-02-07 18:54:21 +00:00
--lefts : [Either a b] -> [a]
lefts es = List.filter isLeft es
2013-02-07 18:54:21 +00:00
--rights : [Either a b] -> [b]
rights es = List.filter isRight es
--partition : [Either a b] -> ([a],[b])
partition es = List.partition isLeft es