Module Base__.Or_error
type 'a t
= ('a, Base.Error.t) Base.Result.t
Serialization and comparison of an
Error
force the error's lazy message.
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> int
val equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> bool
val hash_fold_t : (Base.Hash.state -> 'a -> Base.Hash.state) -> Base.Hash.state -> 'a t -> Base.Hash.state
include Base.Sexpable.S1 with type 'a t := 'a t
val t_of_sexp : (Base.Sexp.t -> 'a) -> Base.Sexp.t -> 'a t
val sexp_of_t : ('a -> Base.Sexp.t) -> 'a t -> Base.Sexp.t
Applicative
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 Base.Applicative.S with type 'a t := 'a t
val apply : ('a -> 'b) t -> 'a t -> 'b t
val map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c t
val map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd t
val all : 'a t list -> 'a list t
val all_unit : unit t list -> unit t
module Applicative_infix : Base__.Applicative_intf.Applicative_infix with type 'a t := 'a t
include Base.Invariant.S1 with type 'a t := 'a t
val invariant : 'a Base__.Invariant_intf.inv -> 'a t Base__.Invariant_intf.inv
include Base.Monad.S with type 'a t := 'a t
include Base__.Monad_intf.S_without_syntax with type 'a t := 'a t
module Monad_infix : Base__.Monad_intf.Infix with type 'a t := 'a t
val return : 'a -> 'a t
return v
returns the (trivial) computation that returns v.
val is_ok : _ t -> bool
val is_error : _ t -> bool
val ignore : _ t -> unit t
val try_with : ?backtrace:bool -> (unit -> 'a) -> 'a t
try_with f
catches exceptions thrown byf
and returns them in theResult.t
as anError.t
.try_with_join
is liketry_with
, except thatf
can throw exceptions or return anError
directly, without ending up with a nested error; it is equivalent toResult.join (try_with f)
.
val try_with_join : ?backtrace:bool -> (unit -> 'a t) -> 'a t
val ok : 'ok t -> 'ok option
ok t
returnsNone
ift
is anError
, and otherwise returns the contents of theOk
constructor.
val ok_exn : 'a t -> 'a
ok_exn t
throws an exception ift
is anError
, and otherwise returns the contents of theOk
constructor.
val of_exn : ?backtrace:[ `Get | `This of string ] -> exn -> _ t
of_exn ?backtrace exn
isError (Error.of_exn ?backtrace exn)
.
val of_exn_result : ?backtrace:[ `Get | `This of string ] -> ('a, exn) Base.Result.t -> 'a t
of_exn_result ?backtrace (Ok a) = Ok a
of_exn_result ?backtrace (Error exn) = of_exn ?backtrace exn
val error : ?strict:unit -> string -> 'a -> ('a -> Base.Sexp.t) -> _ t
error
is a wrapper aroundError.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, ifa
is mutated in the time between the call tocreate
and the sexp conversion, those mutations will be reflected in the sexp. Use~strict:()
to forcesexp_of_a a
to be computed immediately.
val error_s : Base.Sexp.t -> _ t
val error_string : string -> _ t
error_string message
isError (Error.of_string message)
.
val errorf : ('a, unit, string, _ t) Stdlib.format4 -> 'a
errorf format arg1 arg2 ...
isError (sprintf format arg1 arg2 ...)
. Note that it calculates the string eagerly, so when performance matters you may want to useerror
instead.
val tag : 'a t -> tag:string -> 'a t
tag t ~tag
isResult.map_error t ~f:(Error.tag ~tag)
.tag_arg
is similar.
val tag_s : 'a t -> tag:Base.Sexp.t -> 'a t
val tag_arg : 'a t -> string -> 'b -> ('b -> Base.Sexp.t) -> 'a t
val unimplemented : string -> _ t
For 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.
val map : 'a t -> f:('a -> 'b) -> 'b t
val iter : 'a t -> f:('a -> unit) -> unit
val iter_error : _ t -> f:(Base.Error.t -> unit) -> unit
val combine_errors : 'a t list -> 'a list t
combine_errors ts
returnsOk
if every element ints
isOk
, else it returnsError
with all the errors ints
. More precisely:combine_errors [Ok a1; ...; Ok an] = Ok [a1; ...; an]
combine_errors [...; Error e1; ...; Error en; ...] = Error (Error.of_list [e1; ...; en])
val combine_errors_unit : unit t list -> unit t
combine_errors_unit ts
returnsOk
if every element ints
isOk ()
, else it returnsError
with all the errors ints
, likecombine_errors
.
val filter_ok_at_least_one : 'a t list -> 'a list t
filter_ok_at_least_one ts
returns all values ints
that areOk
if there is at least one, otherwise it returns the same error ascombine_errors ts
.