fromMaybe -package:xlsx-tabular -package:rio -package:incipit-base -package:colonnade

The fromMaybe function takes a default value and a Maybe value. If the Maybe is Nothing, it returns the default value; 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 GHC.Internal.Text.Read ( readMaybe )

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

>>> fromMaybe 0 (readMaybe "")
0
The fromMaybe function takes a default value and a Maybe value. If the Maybe is Nothing, it returns the default value; 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
Given a default value and a Maybe, yield the default value if the Maybe argument is Nothing and extract the value out of the Just otherwise.
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
Return the value of an optional value. The default is returned if Nothing. Compare to fromJust.
>>> fromMaybe 2 (sNothing :: SMaybe Integer)
2 :: SInteger

>>> fromMaybe 2 (sJust 5 :: SMaybe Integer)
5 :: SInteger

>>> prove $ \x -> fromMaybe x (sNothing :: SMaybe Integer) .== x
Q.E.D.

>>> prove $ \x -> fromMaybe (x+1) (sJust x :: SMaybe Integer) .== x
Q.E.D.
Operator from maybe type using record extended isNull.
Convert between Nothing and a default value, or Just and its value (not a true bijection).
fromMaybe default m is the a in m if it exists and the default otherwise
Operator from maybe type using record extended isNull.
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
Converts a Maybe value into an Optional one.
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
instance Monad m => Semigroup (FromMaybe m a) where
mappend (FromMaybe f) (FromMaybe g) = FromMaybeM (f . Just . g)
Monadic generalisation of fromMaybe.
Deconstruct MaybeX into an a - the opposite of toMaybeX. Be careful when using this function, because it might return an XException if the argument was IsX.