option
Optional values.
The Option type represents a value that may or may not be present.
Types
Option
Some('t)
None
Functions
is_none
fn(original: Option<'a>) -> Bool
Returns true if the option is None.
import core/option { Some, None }
test.assert(option.is_none(None));
test.assert(!option.is_none(Some(1)));is_some
fn(original: Option<'a>) -> Bool
Returns true if the option contains a value.
import core/option { Some, None }
test.assert(option.is_some(Some(1)));
test.assert(!option.is_some(None));map
fn(original: Option<'b>, map_fun: fn ('b) -> 'b / 't8) -> Option<'b> / 't8
Applies a function to the value inside a Some, or returns None.
import core/option { Some, None }
test.assert_eq(option.map(Some(3), fn(x) { x * 2 }), Some(6));
test.assert_eq(option.map(None, fn(x) { x * 2 }), None);then
fn(condition: Bool, value: 'a) -> Option<'a>
Returns Some(value) if the condition is true, otherwise None.
import core/option { Some, None }
test.assert_eq(option.then(true, 42), Some(42));
test.assert_eq(option.then(false, 42), None);