Module CCOpt

module CCOpt: sig .. end

Options



type 'a t = 'a option 
val map : ('a -> 'b) -> 'a t -> 'b t
Transform the element inside, if any
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'b
map_or ~default f o is f x if o = Some x, default otherwise
Since 0.16
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'b
map_lazy default_fn f o if f o if o = Some x, default_fn () otherwise
Since 1.2
val is_some : 'a t -> bool
val is_none : 'a t -> bool
Since 0.11
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
val return : 'a -> 'a t
Monadic return, that is return x = Some x
val (>|=) : 'a t -> ('a -> 'b) -> 'b t
Infix version of CCOpt.map
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
Monadic bind
val flat_map : ('a -> 'b t) -> 'a t -> 'b t
Flip version of >>=
val map2 : ('a -> 'b -> 'c) -> 'a t -> 'b t -> 'c t
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 filter : ('a -> bool) -> 'a t -> 'a t
Filter on 0 or 1 element
Since 0.5
val if_ : ('a -> bool) -> 'a -> 'a option
if_ f x is Some x if f x, None otherwise
Since 0.17
val exists : ('a -> bool) -> 'a t -> bool
Since 0.17
val for_all : ('a -> bool) -> 'a t -> bool
Since 0.17
val get_or : default:'a -> 'a t -> 'a
get_or ~default o extracts the value from o, or returns default if 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 x unwraps x, but if x = None it 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 xi is 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 x calls f x and returns Some y if f x = y. If f x raises any exception, the result is None. This can be useful to wrap functions such as Map.S.find.
handler : the exception handler, which returns true if the exception is to be caught.
val wrap2 : ?handler:(exn -> bool) -> ('a -> 'b -> 'c) -> 'a -> 'b -> 'c option
wrap2 f x y is similar to wrap1 but for binary functions.

Applicative


val pure : 'a -> 'a t
Alias to CCOpt.return
val (<*>) : ('a -> 'b) t -> 'a t -> 'b t
val (<$>) : ('a -> 'b) -> 'a t -> 'b t

Alternatives


val or_ : else_:'a t -> 'a t -> 'a t
or_ ~else_ a is a if a is Some _, else_ otherwise
Since 1.2
val or_lazy : else_:(unit -> 'a t) -> 'a t -> 'a t
or_lazy else_ a is a if a is Some _, else_ () otherwise
Since 1.2
val (<+>) : 'a t -> 'a t -> 'a t
a <+> b is a if a is Some _, b otherwise
val choice : 'a t list -> 'a t
choice returns the first non-None element of the list, or None

Infix Operators


module Infix: sig .. end

Conversion and IO


val to_list : 'a t -> 'a list
val of_list : 'a list -> 'a t
Head of list, or None
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, 'b) Result.result -> 'a t
Since 1.2
type 'a sequence = ('a -> unit) -> unit 
type 'a gen = unit -> 'a option 
type 'a printer = Format.formatter -> 'a -> unit 
type 'a random_gen = Random.State.t -> 'a 
val random : 'a random_gen -> 'a t random_gen
val choice_seq : 'a t sequence -> 'a t
choice_seq s is similar to CCOpt.choice, but works on sequences. It returns the first Some x occurring in s, or None otherwise.
Since 0.13
val to_gen : 'a t -> 'a gen
val to_seq : 'a t -> 'a sequence
val pp : 'a printer -> 'a t printer