Module CCOpt
Options
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_or ~default f oisf xifo = Some x,defaultotherwise.- since
- 0.16
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'bmap_lazy default_fn f oiff oifo = Some x,default_fn ()otherwise.- since
- 1.2
val is_some : _ t -> boolis_some (Some x)returnstrueotherwise it returnsfalse.
val is_none : _ t -> boolis_none Nonereturnstrueotherwise it returnsfalse.- since
- 0.11
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> intCompare two options, using custom comparators for the value.
Noneis always assumed to be less thanSome _.
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> boolTest for equality between option types using a custom equality predicat.
val return : 'a -> 'a tMonadic return, that is
return x = Some x.
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c tmap2 f o1 o2maps'a optionand'b optionto a'c optionusingf.
val iter : ('a -> unit) -> 'a t -> unitIterate on 0 or 1 element.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'aFold on 0 or 1 element.
val exists : ('a -> bool) -> 'a t -> boolReturn
trueiff there exists an element for which the provided function evaluates totrue.- since
- 0.17
val for_all : ('a -> bool) -> 'a t -> boolReturn
trueiff the provided function evaluates totruefor all elements.- since
- 0.17
val get_or : default:'a -> 'a t -> 'aget_or ~default oextracts the value fromo, or returnsdefaultifo = None.- since
- 0.18
val get_exn : 'a t -> 'aOpen the option, possibly failing if it is
None.- raises Invalid_argument
if the option is
None.
val get_lazy : (unit -> 'a) -> 'a t -> 'aget_lazy default_fn xunwrapsx, but ifx = Noneit returnsdefault_fn ()instead.- since
- 0.6.1
val sequence_l : 'a t list -> 'a list tsequence_l [x1; x2; ...; xn]returnsSome [y1;y2;...;yn]if everyxiisSome yi. Otherwise, if the list contains at least oneNone, the result isNone.
val wrap : ?handler:(exn -> bool) -> ('a -> 'b) -> 'a -> 'b optionwrap f xcallsf xand returnsSome yiff x = y. Iff xraises any exception, the result isNone. This can be useful to wrap functions such asMap.S.find.- parameter handler
the exception handler, which returns
trueif the exception is to be caught.
val wrap2 : ?handler:(exn -> bool) -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'c optionwrap2 f x yis similar towrapbut for binary functions.
Applicative
Alternatives
val or_lazy : else_:(unit -> 'a t) -> 'a t -> 'a tor_lazy ~else_ aisaifaisSome _,else_ ()otherwise.- since
- 1.2
val return_if : bool -> 'a -> 'a tApply
SomeorNonedepending on a boolean. More precisely,return_if false xisNone, andreturn_if true xisSome x.- since
- 2.2
Infix Operators
- since
- 0.16
module Infix : sig ... endLet operators on OCaml >= 4.08.0, nothing otherwise
- since
- 2.8
include CCShimsMkLet_.S with type 'a t_let := 'a option
Conversion and IO
val to_result : 'e -> 'a t -> ('a, 'e) Pervasives.result- since
- 1.2
val to_result_lazy : (unit -> 'e) -> 'a t -> ('a, 'e) Pervasives.result- since
- 1.2
val of_result : ('a, _) Pervasives.result -> 'a t- since
- 1.2
type 'a sequence= ('a -> unit) -> unittype 'a gen= unit -> 'a optiontype 'a printer= Format.formatter -> 'a -> unittype 'a random_gen= Random.State.t -> 'a
val random : 'a random_gen -> 'a t random_genval choice_seq : 'a t sequence -> 'a tchoice_seq sis similar tochoice, but works on sequences. It returns the firstSome xoccurring ins, orNoneotherwise.- since
- 0.13