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 -> boolequal f x ylifts the equality predicatefto option types. That is, if bothxandyareNonethen it returnstrue, if they are bothSome _thenfis called. Otherwise it returnsfalse.
val bind : 'a option -> ('a -> 'b option) -> 'b optionbind x fisf yifxisSome yandNoneotherwise
val filter : ('a -> bool) -> 'a option -> 'a optionfilter f xisxifxSome yandf yis true,Noneotherwise
val flatten : 'a option option -> 'a optionflatten xisSome yifxisSome (Some y)andNoneotherwise.
val append : 'a option -> 'a option -> 'a optionappend x yis the first element of the concatenation ofxandyseen as lists. In other words,append (Some a) yisSome a,append None (Some b)isSome b, andappend None NoneisNone.
"Iterators"
val iter : ('a -> unit) -> 'a option -> unititer f xexecutesf yifxequalsSome y. It does nothing otherwise.
val iter2 : ('a -> 'b -> unit) -> 'a option -> 'b option -> unititer2 f x yexecutesf z wifxequalsSome zandyequalsSome w. It does nothing if bothxandyareNone.- raises Heterogeneous
otherwise.
val map : ('a -> 'b) -> 'a option -> 'b optionmap f xisNoneifxisNoneandSome (f y)ifxisSome y.
val fold_left : ('b -> 'a -> 'b) -> 'b -> 'a option -> 'bfold_left f a xisf a yifxisSome y, andaotherwise.
val fold_left2 : ('a -> 'b -> 'c -> 'a) -> 'a -> 'b option -> 'c option -> 'afold_left2 f a x yisf z wifxisSome zandyisSome w. It isaif bothxandyareNone.- raises Heterogeneous
otherwise.
val fold_right : ('a -> 'b -> 'b) -> 'a option -> 'b -> 'bfold_right f x aisf y aifxisSome y, andaotherwise.
val fold_left_map : ('a -> 'b -> 'a * 'c) -> 'a -> 'b option -> 'a * 'c optionfold_left_map f a xisa, f yifxisSome y, andaotherwise.
More Specific Operations
Smart operations
module Smart : sig ... endOperations with Lists
module List : sig ... end