Module CCOpt
Options
- val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'b
- map_or ~default f ois- f xif- o = Some x,- defaultotherwise.- since
- 0.16
 
- val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'b
- map_lazy default_fn f oif- f oif- o = Some x,- default_fn ()otherwise.- since
- 1.2
 
- val is_some : _ t -> bool
- is_some (Some x)returns- trueotherwise it returns- false.
- val is_none : _ t -> bool
- is_none Nonereturns- trueotherwise it returns- false.- since
- 0.11
 
- val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
- Compare two options, using custom comparators for the value. - Noneis always assumed to be less than- Some _.
- val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
- Test for equality between option types using a custom equality predicat. 
- val return : 'a -> 'a t
- Monadic return, that is - return x = Some x.
- val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
- map2 f o1 o2maps- 'a optionand- 'b optionto a- 'c optionusing- f.
- val iter : ('a -> unit) -> 'a t -> unit
- Iterate on 0 or 1 element. 
- val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'a
- Fold on 0 or 1 element. 
- val exists : ('a -> bool) -> 'a t -> bool
- Return - trueiff there exists an element for which the provided function evaluates to- true.- since
- 0.17
 
- val for_all : ('a -> bool) -> 'a t -> bool
- Return - trueiff the provided function evaluates to- truefor all elements.- since
- 0.17
 
- val get_or : default:'a -> 'a t -> 'a
- get_or ~default oextracts the value from- o, or returns- defaultif- o = None.- since
- 0.18
 
- val get_exn : 'a t -> 'a
- Open the option, possibly failing if it is - None.- raises Invalid_argument
- if the option is - None.
 
- val get_lazy : (unit -> 'a) -> 'a t -> 'a
- get_lazy default_fn xunwraps- x, but if- x = Noneit returns- default_fn ()instead.- since
- 0.6.1
 
- val sequence_l : 'a t list -> 'a list t
- sequence_l [x1; x2; ...; xn]returns- Some [y1;y2;...;yn]if every- xiis- Some yi. Otherwise, if the list contains at least one- None, the result is- None.
- val wrap : ?handler:(exn -> bool) -> ('a -> 'b) -> 'a -> 'b option
- wrap f xcalls- f xand returns- Some yif- f x = y. If- f xraises any exception, the result is- None. This can be useful to wrap functions such as- Map.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 option
- wrap2 f x yis similar to- wrapbut for binary functions.
Applicative
Alternatives
- val or_lazy : else_:(unit -> 'a t) -> 'a t -> 'a t
- or_lazy ~else_ ais- aif- ais- Some _,- else_ ()otherwise.- since
- 1.2
 
- val return_if : bool -> 'a -> 'a t
- Apply - Someor- Nonedepending on a boolean. More precisely,- return_if false xis- None, and- return_if true xis- Some x.- since
- 2.2
 
Infix Operators
- since
- 0.16
module Infix : sig ... endConversion and IO
- val to_result : 'e -> 'a t -> ('a, 'e) Result.result
- since
- 1.2
 
- val to_result_lazy : (unit -> 'e) -> 'a t -> ('a, 'e) Result.result
- since
- 1.2
 
- val of_result : ('a, _) Result.result -> 'a t
- since
- 1.2
 
- type 'a sequence- = ('a -> unit) -> unit
- type 'a gen- = unit -> 'a option
- type 'a printer- = Stdlib.Format.formatter -> 'a -> unit
- type 'a random_gen- = Stdlib.Random.State.t -> 'a
- val random : 'a random_gen -> 'a t random_gen
- val choice_seq : 'a t sequence -> 'a t
- choice_seq sis similar to- choice, but works on sequences. It returns the first- Some xoccurring in- s, or- Noneotherwise.- since
- 0.13