:: a -> Maybe a -> a -package:bytestring-tree-builder

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
asProxyTypeOf is a type-restricted version of const. It is usually used as an infix operator, and its typing forces its first argument (which is usually overloaded) to have the same type as the tag of the second.
>>> import GHC.Internal.Word

>>> :type asProxyTypeOf 123 (Proxy :: Proxy Word8)
asProxyTypeOf 123 (Proxy :: Proxy Word8) :: Word8
Note the lower-case proxy in the definition. This allows any type constructor with just one argument to be passed to the function, for example we could also write
>>> import GHC.Internal.Word

>>> :type asProxyTypeOf 123 (Just (undefined :: Word8))
asProxyTypeOf 123 (Just (undefined :: Word8)) :: Word8
Insert an m between each pair of t m.
>>> intercalate1 ", " $ "hello" :| ["how", "are", "you"]
"hello, how, are, you"
>>> intercalate1 ", " $ "hello" :| []
"hello"
>>> intercalate1 mempty $ "I" :| ["Am", "Fine", "You?"]
"IAmFineYou?"
Flipped version of fromMaybe, useful for chaining.
O(n) Prepend an element.
option x p tries to apply action p. If p fails without consuming input, it returns the value x, otherwise the value returned by p.
priority  = option 0 (digitToInt <$> digit)
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.

Examples

Perform a computation with Maybe and replace the result with a constant value if it is Just:
>>> 'a' <$ Just 2
Just 'a'

>>> 'a' <$ Nothing
Nothing
Replace all locations in the output with the same value. The default definition is contramap . const, but this may be overridden with a more efficient version.
Keep value x alive until computation k completes. Warning: This primop exists for completeness, but it is difficult to use correctly. Prefer keepAliveUnlifted if the value to keep alive is simply a wrapper around an unlifted type (e.g. ByteArray).
Variant of keepAlive in which the value kept alive is of an unlifted boxed type.
O(n) Append an element.
Flipped version of <$.

Examples

Replace the contents of a Maybe Int with a constant String:
>>> Nothing $> "foo"
Nothing
>>> Just 90210 $> "foo"
Just "foo"
Replace the contents of an Either Int Int with a constant String, resulting in an Either Int String:
>>> Left 8675309 $> "foo"
Left 8675309
>>> Right 8675309 $> "foo"
Right "foo"
Replace each element of a list with a constant String:
>>> [1,2,3] $> "foo"
["foo","foo","foo"]
Replace the second element of a pair with a constant String:
>>> (1,2) $> "foo"
(1,"foo")
This is >$ with its arguments flipped.