Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
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.
If you need more Either
functions see the
either.
Synopsis
- fromLeft :: a -> Either a b -> a
- fromRight :: b -> Either a b -> b
- fromEither :: Either a a -> a
- fromLeft' :: Partial => Either l r -> l
- fromRight' :: Partial => Either l r -> r
- eitherToMaybe :: Either a b -> Maybe b
- maybeToEither :: a -> Maybe b -> Either a b
- mapLeft :: (a -> c) -> Either a b -> Either c b
- mapRight :: (b -> c) -> Either a b -> Either a c
Documentation
fromEither :: Either a a -> a Source #
Pull the value out of an Either
where both alternatives
have the same type.
\x -> fromEither (Left x ) == x \x -> fromEither (Right x) == x
fromLeft' :: Partial => Either l r -> l Source #
The fromLeft'
function extracts the element out of a Left
and
throws an error if its argument is Right
.
Much like fromJust
, using this function in polished code is usually a bad idea.
\x -> fromLeft' (Left x) == x \x -> fromLeft' (Right x) == undefined
fromRight' :: Partial => Either l r -> r Source #
The fromRight'
function extracts the element out of a Right
and
throws an error if its argument is Left
.
Much like fromJust
, using this function in polished code is usually a bad idea.
\x -> fromRight' (Right x) == x \x -> fromRight' (Left x) == undefined
eitherToMaybe :: Either a b -> Maybe b Source #
Given an Either
, convert it to a Maybe
, where Left
becomes Nothing
.
\x -> eitherToMaybe (Left x) == Nothing \x -> eitherToMaybe (Right x) == Just x
maybeToEither :: a -> Maybe b -> Either a b Source #
Given a Maybe
, convert it to an Either
, providing a suitable
value for the Left
should the value be Nothing
.
\a b -> maybeToEither a (Just b) == Right b \a -> maybeToEither a Nothing == Left a