Skip to main content
Version: 1.1.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 v_opt : option<int> = Some(1);
let v : int = Option.unopt (v_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 v_opt : option<int> = Some(1);
let v : int = Option.unopt_with_error (v_opt, "FooBar"); /* 1 */
let none : int = Option.unopt_with_error (None() as option<int>, "FooBar"); /* fails with "FooBar" */
let value: (default: 'a, value : option<'a>) => 'a

Returns the value if the second argument is wrapped in the Some constructor, or returns the first argument if it is None.

let value_exn: (err: 'e, value : option<'a>) => 'a

Returns the value if the second argument is wrapped in the Some constructor, or fails with the first value if it is None.

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 called.

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

Returns a boolean signaling if the value is None.

let is_some: option<'a> => bool

Returns a boolean signaling if the value is a Some.