Module Option
Module implementing basic combinators for OCaml option type. It tries follow closely the style of OCaml standard library.
Actually, some operations have the same name as List
ones: they actually are similar considering 'a option
as a type of lists with at most one element.
val equal : ('a -> 'a -> bool) -> 'a option -> 'a option -> bool
equal f x y
lifts the equality predicatef
to option types. That is, if bothx
andy
areNone
then it returnstrue
, if they are bothSome _
thenf
is called. Otherwise it returnsfalse
.
val bind : 'a option -> ('a -> 'b option) -> 'b option
bind x f
isf y
ifx
isSome y
andNone
otherwise
val filter : ('a -> bool) -> 'a option -> 'a option
filter f x
isx
ifx
Some y
andf y
is true,None
otherwise
val flatten : 'a option option -> 'a option
flatten x
isSome y
ifx
isSome (Some y)
andNone
otherwise.
val append : 'a option -> 'a option -> 'a option
append x y
is the first element of the concatenation ofx
andy
seen as lists. In other words,append (Some a) y
isSome a
,append None (Some b)
isSome b
, andappend None None
isNone
.
"Iterators"
val iter : ('a -> unit) -> 'a option -> unit
iter f x
executesf y
ifx
equalsSome y
. It does nothing otherwise.
val iter2 : ('a -> 'b -> unit) -> 'a option -> 'b option -> unit
iter2 f x y
executesf z w
ifx
equalsSome z
andy
equalsSome w
. It does nothing if bothx
andy
areNone
.- raises Heterogeneous
otherwise.
val map : ('a -> 'b) -> 'a option -> 'b option
map f x
isNone
ifx
isNone
andSome (f y)
ifx
isSome y
.
val fold_left : ('b -> 'a -> 'b) -> 'b -> 'a option -> 'b
fold_left f a x
isf a y
ifx
isSome y
, anda
otherwise.
val fold_left2 : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b option -> 'c option -> 'a
fold_left2 f a x y
isf z w
ifx
isSome z
andy
isSome w
. It isa
if bothx
andy
areNone
.- raises Heterogeneous
otherwise.
val fold_right : ('a -> 'b -> 'b) -> 'a option -> 'b -> 'b
fold_right f x a
isf y a
ifx
isSome y
, anda
otherwise.
val fold_left_map : ('a -> 'b -> 'a * 'c) -> 'a -> 'b option -> 'a * 'c option
fold_left_map f a x
isa, f y
ifx
isSome y
, anda
otherwise.
More Specific Operations
Smart operations
module Smart : sig ... end
Operations with Lists
module List : sig ... end