Std.Maybe
Optional values: a type-safe alternative to null.
Types
Maybe
type Maybe a =
| Nothing
| Just aA value that is either present (Just) or absent (Nothing).
Functions
is_just
fun is_just : Maybe a -> BoolReturns True if the value is Just.
is_nothing
fun is_nothing : Maybe a -> BoolReturns True if the value is Nothing.
map
fun map : (f: a -> b) -> (m: Maybe a) -> Maybe bApplies a function to the inner value if Just, otherwise returns Nothing.
unwrap_or
fun unwrap_or : (default: a) -> (m: Maybe a) -> aReturns the inner value or a default if Nothing.
unwrap
fun unwrap : (m: Maybe a) -> a where {a: Debug}Returns the inner value. Panics on Nothing.
and_then
fun and_then : (f: a -> Maybe b) -> (m: Maybe a) -> Maybe bChains a function that returns Maybe. Returns Nothing if the input is Nothing.
or_else
fun or_else : (fallback: Maybe a) -> (m: Maybe a) -> Maybe aReturns the first Just value, or Nothing if both are Nothing.