/// Optional values (`Option` is in the prelude).
///
/// `Option` is for a value that may be absent, where absence is not a
/// failure (a key not in a dictionary, a variable not set). A failure with
/// a reason is a `Result` (ADR 0024); `to_result` turns one into the other.
/// Whether `o` is `Some`.
pub fn is_some :: o: Option -> Bool
{
match o { Some(_) -> True, None -> False }
}
/// Whether `o` is `None`.
pub fn is_none :: o: Option -> Bool
{
match o { Some(_) -> False, None -> True }
}
/// Apply `f` to the value of a `Some`.
pub fn map :: o: Option f: fn(a) -> b / -> Option /
{
match o { Some(x) -> Some(f x), None -> None }
}
/// Continue with `next` on `Some`; for `use`:
/// `use user <- option.then(find_user(name))`.
pub fn then :: o: Option next: fn(a) -> Option / -> Option /
{
match o { Some(x) -> next x, None -> None }
}
/// The value of a `Some`, or `default`.
pub fn unwrap_or :: o: Option default: a -> a
{
match o { Some(x) -> x, None -> default }
}
/// `Ok` with the value of a `Some`, or `Error(reason)`: absence becomes
/// a failure with a reason.
pub fn to_result :: o: Option reason: x -> Result
{
match o { Some(x) -> Ok(x), None -> Error(reason) }
}
/// The values of the `Some`s, in order.
pub fn values :: options: List