:: a -> Maybe a -> a package:classy-prelude

The fromMaybe function takes a default value and and Maybe value. If the Maybe is Nothing, it returns the default values; otherwise, it returns the value contained in the Maybe.

Examples

Basic usage:
>>> fromMaybe "" (Just "Hello, World!")
"Hello, World!"
>>> fromMaybe "" Nothing
""
Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:
>>> import Text.Read ( readMaybe )

>>> fromMaybe 0 (readMaybe "5")
5

>>> fromMaybe 0 (readMaybe "")
0
Replace all locations in the input with the same value. The default definition is fmap . const, but this may be overridden with a more efficient version. Using ApplicativeDo: 'a <$ bs' can be understood as the do expression
do bs
pure a
with an inferred Functor constraint.