Type for tracking errors in an Error.t. This is a specialization of the Result type, where the Error constructor carries an Error.t.
A common idiom is to wrap a function that is not implemented on all platforms, e.g.:
val do_something_linux_specific : (unit -> unit) Or_error.t
include sig ... endval t_of_sexp : (Base__.Sexplib.Sexp.t ‑> 'a) ‑> Base__.Sexplib.Sexp.t ‑> 'a tval sexp_of_t : ('a ‑> Base__.Sexplib.Sexp.t) ‑> 'a t ‑> Base__.Sexplib.Sexp.tval hash_fold_t : (Base__.Ppx_hash_lib.Std.Hash.state ‑> 'a ‑> Base__.Ppx_hash_lib.Std.Hash.state) ‑> Base__.Ppx_hash_lib.Std.Hash.state ‑> 'a t ‑> Base__.Ppx_hash_lib.Std.Hash.stateApplicative functions don't have quite the same semantics as
Applicative.of_Monad(Or_error) would give -- apply (Error e1) (Error e2) returns
the combination of e1 and e2, whereas it would only return e1 if it were defined
using bind.
include Applicative.S with type a t := a tval return : 'a ‑> 'a tmodule Applicative_infix : sig ... endinclude Container.S1 with type a t := a tval mem : 'a t ‑> 'a ‑> equal:('a ‑> 'a ‑> bool) ‑> boolChecks whether the provided element is there, using equal.
val length : 'a t ‑> intval is_empty : 'a t ‑> boolval iter : 'a t ‑> f:('a ‑> unit) ‑> unitval fold : 'a t ‑> init:'accum ‑> f:('accum ‑> 'a ‑> 'accum) ‑> 'accumfold t ~init ~f returns f (... f (f (f init e1) e2) e3 ...) en, where e1..en
are the elements of t
val fold_result : 'a t ‑> init:'accum ‑> f:('accum ‑> 'a ‑> ('accum, 'e) Result.t) ‑> ('accum, 'e) Result.tfold_result t ~init ~f is a short-circuiting version of fold that runs in the
Result monad. If f returns an Error _, that value is returned without any
additional invocations of f.
val fold_until : 'a t ‑> init:'accum ‑> f:('accum ‑> 'a ‑> ('accum, 'stop) Container_intf.Continue_or_stop.t) ‑> ('accum, 'stop) Container_intf.Finished_or_stopped_early.tfold_until t ~init ~f is a short-circuiting version of fold. If f
returns Stop _ the computation ceases and results in that value. If f returns
Continue _, the fold will proceed.
val exists : 'a t ‑> f:('a ‑> bool) ‑> boolReturns true if and only if there exists an element for which the provided
function evaluates to true. This is a short-circuiting operation.
val for_all : 'a t ‑> f:('a ‑> bool) ‑> boolReturns true if and only if the provided function evaluates to true for all
elements. This is a short-circuiting operation.
val count : 'a t ‑> f:('a ‑> bool) ‑> intReturns the number of elements for which the provided function evaluates to true.
val sum : (module Commutative_group.S with type t = 'sum) ‑> 'a t ‑> f:('a ‑> 'sum) ‑> 'sumReturns the sum of f i for i in the container
val find : 'a t ‑> f:('a ‑> bool) ‑> 'a optionReturns as an option the first element for which f evaluates to true.
val find_map : 'a t ‑> f:('a ‑> 'b option) ‑> 'b optionReturns the first evaluation of f that returns Some, and returns None if there
is no such element.
val to_list : 'a t ‑> 'a listval to_array : 'a t ‑> 'a arrayval min_elt : 'a t ‑> cmp:('a ‑> 'a ‑> int) ‑> 'a optionReturns a minimum (resp maximum) element from the collection using the provided
cmp function, or None if the collection is empty. In case of a tie, the first
element encountered while traversing the collection is returned. The implementation
uses fold so it has the same complexity as fold.
val max_elt : 'a t ‑> cmp:('a ‑> 'a ‑> int) ‑> 'a optioninclude Invariant.S1 with type a t := a tval invariant : 'a Base__.Invariant_intf.inv ‑> 'a t Base__.Invariant_intf.invinclude Monad.S with type a t := a tinclude Base__.Monad_intf.S_without_syntax with type a t := a ttype 'a tA monad is an abstraction of the concept of sequencing of computations. A value of type 'a monad represents a computation that returns a value of type 'a.
include Base__.Monad_intf.Infix with type a t := a tmodule Monad_infix : Base__.Monad_intf.Infix with type a t := a tval try_with : ?backtrace:bool ‑> (unit ‑> 'a) ‑> 'a ttry_with f catches exceptions thrown by f and returns them in the Result.t as an
Error.t. try_with_join is like try_with, except that f can throw exceptions or
return an Error directly, without ending up with a nested error; it is equivalent to
Result.join (try_with f).
val ok_exn : 'a t ‑> 'aok_exn t throws an exception if t is an Error, and otherwise returns the
contents of the Ok constructor.
val of_exn : ?backtrace:[ `Get | `This of string ] ‑> exn ‑> _ tof_exn exn is Error (Error.of_exn exn).
error is a wrapper around Error.create:
error ?strict message a sexp_of_a
= Error (Error.create ?strict message a sexp_of_a)
As with Error.create, sexp_of_a a is lazily computed, when the info is converted
to a sexp. So, if a is mutated in the time between the call to create and the
sexp conversion, those mutations will be reflected in the sexp. Use ~strict:() to
force sexp_of_a a to be computed immediately.
val errorf : ('a, unit, string, _ t) Pervasives.format4 ‑> 'aerrorf format arg1 arg2 ... is Error (sprintf format arg1 arg2 ...). Note that it
calculates the string eagerly, so when performance matters you may want to use error
instead.
val unimplemented : string ‑> _ tFor marking a given value as unimplemented. Typically combined with conditional compilation, where on some platforms the function is defined normally, and on some platforms it is defined as unimplemented. The supplied string should be the name of the function that is unimplemented.
combine_errors ts returns Ok if every element in ts is Ok, else it returns
Error with all the errors in ts. More precisely:
combine_errors [Ok a1; ...; Ok an] = Ok [a1; ...; an] combine_errors [...; Error e1; ...; Error en; ...]
= Error (Error.of_list [e1; ...; en]) combine_errors_unit returns Ok if every element in ts is Ok (), else it
returns Error with all the errors in ts, like combine_errors.
filter_ok_at_least_one ts returns all values in ts that are Ok if there is at
least one, otherwise it returns the same error as combine_errors ts.