MaybeT package:rebase

The parameterizable maybe monad, obtained by composing an arbitrary monad with the Maybe monad. Computations are actions that may produce a value or exit. The return function yields a computation that produces that value, while >>= sequences two subcomputations, exiting if either computation does.
Convert a MaybeT computation to ExceptT, with a default exception value.
Maybe produce a Left, otherwise produce a Right.
>>> maybeToLeft "default" (Just 12)
Left 12
>>> maybeToLeft "default" Nothing
Right "default"
The maybeToList function returns an empty list when given Nothing or a singleton list when given Just.

Examples

Basic usage:
>>> maybeToList (Just 7)
[7]
>>> maybeToList Nothing
[]
One can use maybeToList to avoid pattern matching when combined with a function that (safely) works on lists:
>>> import Text.Read ( readMaybe )

>>> sum $ maybeToList (readMaybe "3")
3

>>> sum $ maybeToList (readMaybe "")
0
Maybe produce a Right, otherwise produce a Left.
>>> maybeToRight "default" (Just 12)
Right 12
>>> maybeToRight "default" Nothing
Left "default"
Convert a ExceptT computation to MaybeT, discarding the value of any exception.
Transform the computation inside a MaybeT.