maybe_default: Provide a default value, turning an optional value into a...

Description Usage Arguments Format Details Value See Also Examples

Description

For when you truly need to unpack the original value before you can continue operations. Try to avoid using this. Preferably, it should only be used at the end of a chain of function calls - all preceding function calls should be lifted to operate on Maybe types.

Usage

1
maybe_default(m, default)

Arguments

m

A Maybe type object (Just or Nothing)

default

A value to return if m is Nothing. Cannot be null.

Format

maybe_default :: Maybe a -> a -> a

Details

N.B. Don't access the maybe element of the underlying list directly (i.e, never write my_value$value), always access the value using maybe_default().

Value

The contained value or, if m is Nothing, the default value

See Also

Other Maybe functions: as_maybe, is_nothing, maybe_apply, maybe_bind, maybe_map_2, maybe_map_3, maybe_map_4, maybe_map_5, maybe_map, maybe_then, maybes_collapse, maybes_partition

Examples

1
2
maybe_default(Just(42), 100) # 42
maybe_default(Nothing(), 100) # 100

Teresa00/hfmAnnotation documentation built on May 14, 2019, 12:51 a.m.