package core
Module Core.Option
This module extends Base.Option with bin_io, quickcheck, and support for ppx_optional.
type 'a t = 'a Base.Option.tinclude 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.tinclude 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.tType and Interfaces
val hash_fold_t :
(Base.Hash.state -> 'a -> Base.Hash.state) ->
Base.Hash.state ->
'a option ->
Base.Hash.stateval t_sexp_grammar :
'a Sexplib0.Sexp_grammar.t ->
'a option Sexplib0.Sexp_grammar.tinclude Base.Equal.S1 with type 'a t := 'a option
val equal : 'a Base.Equal.equal -> 'a option Base.Equal.equalinclude Base.Invariant.S1 with type 'a t := 'a option
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.tApplicative interface
Options form an applicative, where:
return x = Some xNone <*> x = NoneSome f <*> None = NoneSome f <*> Some x = Some (f x)
include Base.Applicative.S with type 'a t := 'a option
module Applicative_infix = Base.Option.Applicative_infixMonadic interface
Options form a monad, where:
return x = Some x(None >>= f) = None(Some x >>= f) = f x
include Base.Monad.S with type 'a t := 'a option
t >>= f returns a computation that sequences the computations represented by two monad elements. The resulting computation first does t to yield a value v, and then runs the computation returned by f v.
module Monad_infix = Base.Option.Monad_infixignore_m t is map t ~f:(fun _ -> ()). ignore_m used to be called ignore, but we decided that was a bad name, because it shadowed the widely used Caml.ignore. Some monads still do let ignore = ignore_m for historical reasons.
Like all, but ensures that every monadic value in the list produces a unit value, all of which are discarded rather than being collected into a list.
module Let_syntax = Base.Option.Let_syntaxExtracting Underlying Values
Extracts the underlying value if present, otherwise returns default.
val value_exn :
?here:Caml.Lexing.position ->
?error:Base.Error.t ->
?message:string ->
'a option ->
'aExtracts the underlying value, or raises if there is no value present. The error raised can be augmented using the ~here, ~error, and ~message optional arguments.
Extracts the underlying value and applies f to it if present, otherwise returns default.
Extracts the underlying value if present, otherwise executes and returns the result of default. default is only executed if the underlying value is absent.
On None, returns init. On Some x, returns f init x.
Checks whether the provided element is there, using equal.
find t ~f returns t if t = Some x and f x = true; otherwise, find returns None.
On None, returns None. On Some x, returns f x.
call x f runs an optional function ~f on the argument.
merge a b ~f merges together the values from a and b using f. If both a and b are None, returns None. If only one is Some, returns that one, and if both are Some, returns Some of the result of applying f to the contents of a and b.
Constructors
try_with f returns Some x if f returns x and None if f raises an exception. See Result.try_with if you'd like to know which exception.
try_with_join f returns the optional value returned by f if it exits normally, and None if f raises an exception.
first_some t1 t2 returns t1 if it has an underlying value, or t2 otherwise.
some_if b x converts a value x to Some x if b, and None otherwise.
Predicates
include Comparator.Derived with type 'a t := 'a t
val comparator :
('a, 'cmp) Base.Comparator.comparator ->
('a t, 'cmp comparator_witness) Base.Comparator.comparatorinclude 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.tval validate :
none:unit Validate.check ->
some:'a Validate.check ->
'a t Validate.checkmodule 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_syntax on 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 supports Optional_syntax. Since Optional_syntax can only be opted into at the granularity of the whole match expression, we need this Optional_syntax support for options in order to use it for the other half of the tuple.