Safe Haskell | Safe-Inferred |
---|
Data.Either.Extra
Description
This module extends Data.Either with extra operations, particularly
to quickly extract from inside an Either
. Some of these operations are
partial, and should be used with care in production-quality code.
- isLeft :: Either l r -> Bool
- isRight :: Either l r -> Bool
- fromLeft :: a -> Either a b -> a
- fromRight :: b -> Either a b -> b
- fromEither :: Either a a -> a
Documentation
isLeft :: Either l r -> Bool
Test if an Either
value is the Left
constructor.
Provided as standard with GHC 7.8 and above.
isRight :: Either l r -> Bool
Test if an Either
value is the Right
constructor.
Provided as standard with GHC 7.8 and above.
fromLeft :: a -> Either a b -> a
Return the contents of a Left
-value or a default value otherwise.
fromLeft 1 (Left 3) == 3 fromLeft 1 (Right "foo") == 1
fromRight :: b -> Either a b -> b
Return the contents of a Right
-value or a default value otherwise.
fromRight 1 (Right 3) == 3 fromRight 1 (Left "foo") == 1
fromEither :: Either a a -> a
Pull the value out of an Either
where both alternatives
have the same type.
\x -> fromEither (Left x ) == x \x -> fromEither (Right x) == x