CCOptionBasic operations on the option type.
This module replaces `CCOpt`.
The type for option values. Either None or a value Some v.
value o ~default is v if o is Some v and default otherwise.
bind o f is f v if o is Some v and None if o is None.
join oo is Some v if oo is Some (Some v) and None otherwise.
map f o is None if o is None and Some (f v) if o is Some v.
equal eq o0 o1 is true if and only if o0 and o1 are both None or if they are Some v0 and Some v1 and eq v0 v1 is true.
compare cmp o0 o1 is a total order on options using cmp to compare values wrapped by Some _. None is smaller than Some _ values.
val to_seq : 'a option -> 'a Stdlib.Seq.tto_seq o is o as a sequence. None is the empty sequence and Some v is the singleton sequence containing v.
val map_or : default:'b -> ('a -> 'b) -> 'a t -> 'bmap_or ~default f o is f x if o = Some x, default otherwise.
val map_lazy : (unit -> 'b) -> ('a -> 'b) -> 'a t -> 'bmap_lazy default_fn f o is f x if o = Some x, default_fn () otherwise.
val return : 'a -> 'a treturn x is a monadic return, that is return x = Some x.
val flat_map_l : ('a -> 'b list) -> 'a t -> 'b listflat_map_l f o is [] if o is None, or f x if o is Some x.
Kleisli composition. Monadic equivalent of CCFun.compose
map2 f o1 o2 maps 'a option and 'b option to a 'c option using f.
val fold : ('a -> 'b -> 'a) -> 'a -> 'b t -> 'afold f init o is f init x if o is Some x, or init if o is None. Fold on 0 or 1 element.
filter f o returns Some x if o is Some x and f x is true, or None if f x is false or if o is None. Filter on 0 or 1 element.
val exists : ('a -> bool) -> 'a t -> boolexists f o returns true iff there exists an element for which the provided function f evaluates to true.
val for_all : ('a -> bool) -> 'a t -> boolfor_all f o returns true iff the provided function f evaluates to true for all elements.
val get_or : default:'a -> 'a t -> 'aget_or ~default o extracts the value from o, or returns default if o is None.
val apply_or : ('a -> 'a t) -> 'a -> 'aapply_or f x returns the original x if f fails, or unwraps f x if it succeeds. Useful for piping preprocessing functions together (such as string processing), turning functions like "remove" into "remove_if_it_exists".
val get_exn : 'a t -> 'aget_exn o returns x if o is Some x or fails if o is None.
val get_exn_or : string -> 'a t -> 'aget_exn_or msg o returns x if o is Some x or fails with Invalid_argument msg if o is None.
val get_lazy : (unit -> 'a) -> 'a t -> 'aget_lazy default_fn o unwraps o, but if o is None it returns default_fn () instead.
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.
wrap ?handler 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.
wrap2 ?handler f x y is similar to wrap but for binary functions.
or_lazy ~else_ o is o if o is Some _, else_ () if o is None.
val return_if : bool -> 'a -> 'a treturn_if b x applies Some or None depending on the boolean b. More precisely, return_if false x is None, and return_if true x is Some x.
module Infix : sig ... endval of_list : 'a list -> 'a tof_list l returns Some x (x being the head of the list l), or None if l is the empty list.
to_result e o returns Ok x if o is Some x, or Error e if o is None.
to_result_lazy f o returns Ok x if o is Some x or Error f if o is None.
type 'a printer = Stdlib.Format.formatter -> 'a -> unittype 'a random_gen = Stdlib.Random.State.t -> 'aval random : 'a random_gen -> 'a t random_genchoice_iter iter is similar to choice, but works on iter. It returns the first Some x occurring in iter, or None otherwise.
val choice_seq : 'a t Stdlib.Seq.t -> 'a tchoice_seq seq works on Seq.t. It returns the first Some x occurring in seq, or None otherwise.
to_gen o is o as a gen. Some x is the singleton gen containing x and None is the empty gen.