Options
type 'a t = 'a option =
| None
| Some of 'a
The type for option values. Either
None
or a valueSome v
.
val value : 'a option -> default:'a -> 'a
value o ~default
isv
ifo
isSome v
anddefault
otherwise.
val bind : 'a option -> ('a -> 'b option) -> 'b option
bind o f
isf v
ifo
isSome v
andNone
ifo
isNone
.
val join : 'a option option -> 'a option
join oo
isSome v
ifoo
isSome (Some v)
andNone
otherwise.
val map : ('a -> 'b) -> 'a option -> 'b option
map f o
isNone
ifo
isNone
andSome (f v)
iso
isSome v
.
val fold : none:'a -> some:('b -> 'a) -> 'b option -> 'a
fold ~none ~some o
isnone
ifo
isNone
andsome v
ifo
isSome v
.
Predicates and comparisons
val equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool
equal eq o0 o1
istrue
iffo0
ando1
are bothNone
or if they areSome v0
andSome v1
andeq v0 v1
istrue
.
val compare : ('a -> 'a -> int) -> 'a option -> 'a option -> int
compare cmp o0 o1
is a total order on options usingcmp
to compare values wrapped bySome _
.None
is smaller thanSome _
values.
Converting
val to_result : none:'e -> 'a option -> ('a, 'e) Stdlib.result
to_result ~none o
isOk v
ifo
isSome v
andError none
otherwise.
val to_seq : 'a option -> 'a Stdlib.Seq.t
to_seq o
iso
as a sequence.None
is the empty sequence andSome v
is the singleton sequence containingv
.