:: Either a b -> a
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
Extracts the element out of a
Left and throws an error if its
argument take the form
Right _.
Using
Control.Lens:
fromLeft' x ≡ x^?!_Left
>>> fromLeft' (Left 12)
12
Take a Left to a value, crashes on a Right
Extracts the element out of a
Left and throws an error if the
argument is a
Right.
The
fromLeft function extracts the element out of a
Left
and throws an error if its argument take the form
Right _.
fromLeft but with a better error message if it fails. Use
this only where it shouldn't fail!
Safe projection from
Left.
maybeLeft (Left a) = Just a
maybeLeft Right{} = Nothing
Maps left part of
Either to
Maybe.
>>> leftToMaybe (Left True)
Just True
>>> leftToMaybe (Right "aba")
Nothing
Return value on the
Left and fail otherwise