type 'a t = 'a Base.Option.t
include Bin_prot.Binable.S1 with type 'a t := 'a t
val bin_shape_t : Bin_prot.Shape.t -> Bin_prot.Shape.tval bin_size_t : ('a, 'a t) Bin_prot.Size.sizer1val bin_write_t : ('a, 'a t) Bin_prot.Write.writer1val bin_read_t : ('a, 'a t) Bin_prot.Read.reader1val __bin_read_t__ : ('a, int -> 'a t) Bin_prot.Read.reader1val bin_writer_t : ('a, 'a t) Bin_prot.Type_class.S1.writerval bin_reader_t : ('a, 'a t) Bin_prot.Type_class.S1.readerval bin_t : ('a, 'a t) Bin_prot.Type_class.S1.t
include Typerep_lib.Typerepable.S1 with type 'a t := 'a t
val typerep_of_t : 'a Typerep_lib.Std_internal.Typerep.t -> 'a t Typerep_lib.Std_internal.Typerep.tval typename_of_t : 'a Typerep_lib.Typename.t -> 'a t Typerep_lib.Typename.t
include module type of sig ... end with type 'a Option.t := 'a option
include module type of Base.Option with type 'a t := 'a option
val compare : ('a -> 'a -> int) -> 'a option -> 'a option -> intval hash_fold_t : (Base.Hash.state -> 'a -> Base.Hash.state) -> Base.Hash.state -> 'a option -> Base.Hash.state
include Base.Sexpable.S1 with type 'a t := 'a option
val t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a optionval sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a option -> Sexplib0.Sexp.t
val t_sexp_grammar : Base.Sexp.Private.Raw_grammar.t
include Base.Container.S1 with type 'a t := 'a option
val mem : 'a option -> 'a -> equal:('a -> 'a -> bool) -> boolChecks whether the provided element is there, using
equal.
val length : 'a option -> intval is_empty : 'a option -> boolval iter : 'a option -> f:('a -> unit) -> unitval fold : 'a option -> init:'accum -> f:('accum -> 'a -> 'accum) -> 'accumfold t ~init ~freturnsf (... f (f (f init e1) e2) e3 ...) en, wheree1..enare the elements oft
val fold_result : 'a option -> init:'accum -> f:('accum -> 'a -> ('accum, 'e) Base.Result.t) -> ('accum, 'e) Base.Result.tfold_result t ~init ~fis a short-circuiting version offoldthat runs in theResultmonad. Iffreturns anError _, that value is returned without any additional invocations off.
val fold_until : 'a option -> init:'accum -> f:('accum -> 'a -> ('accum, 'final) Base__Container_intf.Export.Continue_or_stop.t) -> finish:('accum -> 'final) -> 'finalfold_until t ~init ~f ~finishis a short-circuiting version offold. IffreturnsStop _the computation ceases and results in that value. IffreturnsContinue _, the fold will proceed. Iffnever returnsStop _, the final result is computed byfinish.Example:
type maybe_negative = | Found_negative of int | All_nonnegative of { sum : int } (** [first_neg_or_sum list] returns the first negative number in [list], if any, otherwise returns the sum of the list. *) let first_neg_or_sum = List.fold_until ~init:0 ~f:(fun sum x -> if x < 0 then Stop (Found_negative x) else Continue (sum + x)) ~finish:(fun sum -> All_nonnegative { sum }) ;; let x = first_neg_or_sum [1; 2; 3; 4; 5] val x : maybe_negative = All_nonnegative {sum = 15} let y = first_neg_or_sum [1; 2; -3; 4; 5] val y : maybe_negative = Found_negative -3
val exists : 'a option -> f:('a -> bool) -> boolReturns
trueif and only if there exists an element for which the provided function evaluates totrue. This is a short-circuiting operation.
val for_all : 'a option -> f:('a -> bool) -> boolReturns
trueif and only if the provided function evaluates totruefor all elements. This is a short-circuiting operation.
val count : 'a option -> f:('a -> bool) -> intReturns the number of elements for which the provided function evaluates to true.
val sum : (module Base__Container_intf.Summable with type t = 'sum) -> 'a option -> f:('a -> 'sum) -> 'sumReturns the sum of
f ifor alliin the container.
val find : 'a option -> f:('a -> bool) -> 'a optionReturns as an
optionthe first element for whichfevaluates to true.
val find_map : 'a option -> f:('a -> 'b option) -> 'b optionReturns the first evaluation of
fthat returnsSome, and returnsNoneif there is no such element.
val to_list : 'a option -> 'a listval to_array : 'a option -> 'a arrayval min_elt : 'a option -> compare:('a -> 'a -> int) -> 'a optionReturns a minimum (resp maximum) element from the collection using the provided
comparefunction, orNoneif the collection is empty. In case of a tie, the first element encountered while traversing the collection is returned. The implementation usesfoldso it has the same complexity asfold.
include Base.Equal.S1 with type 'a t := 'a option
val equal : 'a Base.Equal.equal -> 'a option Base.Equal.equal
include Base.Invariant.S1 with type 'a t := 'a option
Options form a monad, where return x = Some x, (None >>= f) = None, and (Some x
>>= f) = f x.
include Base.Monad.S with type 'a t := 'a option
module Monad_infix : sig ... endmodule Let_syntax : sig ... endval value_map : 'a option -> default:'b -> f:('a -> 'b) -> 'bvalue_map ~default ~fis the same asfunction Some x -> f x | None -> default.
val map2 : 'a option -> 'a option -> f:('a -> 'b -> 'c) -> 'a optionmap2 o fmaps'a optionand'b optionto a'c optionusing~f.
val value_exn : ?here:Caml.Lexing.position -> ?error:Base.Error.t -> ?message:string -> 'a option -> 'avalue_exn (Some x)=x.value_exn Noneraises an error whose contents contain the supplied~here,~error, andmessage, or a default message if none are supplied.
val some : 'a -> 'a optionval both : 'a option -> 'a option -> 'a optionval first_some : 'a option -> 'a option -> 'a optionval some_if : bool -> 'a -> 'a optionval merge : 'a option -> 'a option -> f:('a -> 'a -> 'a) -> 'a optionmerge a b ~fmerges together the values fromaandbusingf. If bothaandbareNone, returnsNone. If only one isSome, returns that one, and if both areSome, returnsSomeof the result of applyingfto the contents ofaandb.
val filter : 'a option -> f:('a -> bool) -> 'a optionval try_with : (unit -> 'a) -> 'a optiontry_with freturnsSome xiffreturnsxandNoneiffraises an exception. SeeResult.try_withif you'd like to know which exception.
val try_with_join : (unit -> 'a option) -> 'a optiontry_with_join freturns the optional value returned byfif it exits normally, andNoneiffraises an exception.
val validate : none:unit Base.Validate.check -> some:'a Base.Validate.check -> 'a option Base.Validate.check
include Comparator.Derived with type 'a t := 'a t
val comparator : ('a, 'cmp) Comparator.comparator -> ('a t, 'cmp comparator_witness) Comparator.comparator
include Quickcheckable.S1 with type 'a t := 'a t
val quickcheck_generator : 'a Base_quickcheck.Generator.t -> 'a t Base_quickcheck.Generator.tval quickcheck_observer : 'a Base_quickcheck.Observer.t -> 'a t Base_quickcheck.Observer.tval quickcheck_shrinker : 'a Base_quickcheck.Shrinker.t -> 'a t Base_quickcheck.Shrinker.t
module Stable : sig ... endmodule Optional_syntax : Optional_syntax.S1 with type 'a t := 'a t and type 'a value := 'aYou might think that it's pointless to have
Optional_syntaxon options because OCaml already has nice syntax for matching on options. The reason to have this here is that you might have, for example, a tuple of an option and some other type that supportsOptional_syntax. SinceOptional_syntaxcan only be opted into at the granularity of the whole match expression, we need thisOptional_syntaxsupport for options in order to use it for the other half of the tuple.