elm/core/Either.elm

22 lines
519 B
Elm
Raw Normal View History

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 = Elm.List.filter isLeft
2013-02-07 18:54:21 +00:00
rights : [Either a b] -> [b]
rights = Elm.List.filter isRight
2013-02-07 18:54:21 +00:00
partition : [Either a b] -> ([a],[b])
partition = Elm.List.partition isLeft