:: String -> Maybe a -> Either String a
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
Convert a Maybe to an Either.
Maybe produce a
Right, otherwise produce a
Left.
>>> maybeToRight "default" (Just 12)
Right 12
>>> maybeToRight "default" Nothing
Left "default"
A
fromJust that fails in the
Either monad
Convert a
Maybe to an
Either.
If the
Maybe is
Just, then return the value in
Right.
>>> maybeToEither 3 $ Just "hello"
Right "hello"
If the
Maybe is
Nothing, then use the given
e
as
Left.
>>> maybeToEither 3 Nothing
Left 3
Maps
Maybe to
Either wrapping default value into
Left.
>>> maybeToRight True (Just "aba")
Right "aba"
>>> maybeToRight True Nothing
Left True
A
fliped version of
maybeToEither.
>>> maybeToEitherOr (Just "hello") 3
Right "hello"
>>> maybeToEitherOr Nothing 3
Left 3