Version: 0.40.0

Option

let unopt: option<'a> => 'a

Returns the value if it is wrapped in the Some constructor

This function fails if the value is None.

let value_opt : option<int> = Some(1);
let value : int = Option.unopt (value_opt); /* 1 */
let none : int = Option.unopt (None() as option<int>); /* fails with "option is None" */
let unopt_with_error: (value : option<'a>, error_msg : string) => 'a

Returns the value if it is wrapped in the Some constructor

This function fails with the provided message if the value is None.

let value_opt : option<int> = Some(1);
let value : int = Option.unopt_with_error (value_opt, "FooBar"); /* 1 */
let none : int = Option.unopt_with_error (None() as option<int>, "FooBar"); /* fails with "FooBar" */
let map: (f : ((item: 'a) => 'b), value : option<'a>) => option<'b>

Applies the mapper function to the value if it is wrapped in the Some constructor.

If the value is None the function is not executed/applied.

let value : option<int> = Some(1);
let foo = (_ : int) : string => "foo";
let foo_option : option<string> = Option.map (foo, value); /* Some "foo" */
let none : option<string> = Option.map (foo, None() as option<int>); /* None */