Option
val unopt : 'a option -> 'a
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 : int option = Some 1
let v : int = Option.unopt v_opt (* 1 *)
let none : int = Option.unopt (None : int option) (* fails with "option 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" */
val unopt_with_error : 'a option -> string -> 'a
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 : int option = Some 1
let v : int = Option.unopt_with_error v_opt "FooBar" (* 1 *)
let none : int = Option.unopt_with_error (None : int option) "FooBar" (* fails with "FooBar" *)
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" */
val value : 'a -> 'a option -> 'a
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
.
val value_exn : 'e -> 'a option -> 'a
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
.
val map : ('a -> 'b) -> 'a option -> 'b option
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 : int option = Some 1
let foo (_ : int) : string = "foo"
let foo_option : string option = Option.map foo v (* Some "foo" *)
let none : string option = Option.map foo (None : int option) (* None *)
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 */
val is_none : 'a option -> bool
let is_none: option<'a> => bool
Returns a boolean signaling if the value is None
.
val is_some : 'a option -> bool
let is_some: option<'a> => bool
Returns a boolean signaling if the value is a Some
.