Option
Option module: operations on Option(a) = Some(a) None
All functions are pure. The type Option(a) is a builtin with constructors Some and None.
Functions
Extracts the value from Some(x), panicking with the given message if None. Use when you are certain the option is Some.
The panic message is prefixed with the module name and `on None` so
it is clearly attributable when it shows up in a stack trace.Returns None if the value does not satisfy pred.
Applies f (which itself returns an Option) and flattens the result.
Returns true if the option is None.
march> Option.is_none(None)
true
march> Option.is_none(Some(0))
falseReturns true if the option contains a value.
march> Option.is_some(Some(42))
true
march> Option.is_some(None)
falseApplies f to the contained value, or returns None.
Returns f() if None, or the original Some value.
Converts Option(a) to a List: Some(x) becomes [x], None becomes [].
Converts Option(a) to Result(a, e) using the provided error value.
Extracts the value from Some(x), panicking if None.
march> Option.unwrap(Some(42))
42
march> Option.unwrap(None)
** panic: Option.unwrap called on NoneReturns the contained value, or default if None.
march> Option.unwrap_or(Some(7), 0)
7
march> Option.unwrap_or(None, 99)
99Returns the contained value, or calls f to produce a default.
Combines two Options into a tuple Option, returning None if either is None.