MaybeT package:base

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 GHC.Internal.Text.Read ( readMaybe )

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

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