Module Base.Or_error
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.ttype 'a t= ('a, Error.t) Result.tSerialization and comparison of an
Errorforce the error's lazy message.
val compare : ('a -> 'a -> int) -> 'a t -> 'a t -> intval equal : ('a -> 'a -> bool) -> 'a t -> 'a t -> boolval hash_fold_t : (Hash.state -> 'a -> Hash.state) -> Hash.state -> 'a t -> Hash.state
include Sexpable.S1 with type 'a t := 'a t
val t_of_sexp : (Sexplib0.Sexp.t -> 'a) -> Sexplib0.Sexp.t -> 'a tval sexp_of_t : ('a -> Sexplib0.Sexp.t) -> 'a t -> Sexplib0.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 Applicative.S with type 'a t := 'a t
val apply : ('a -> 'b) t -> 'a t -> 'b tval map2 : 'a t -> 'b t -> f:('a -> 'b -> 'c) -> 'c tval map3 : 'a t -> 'b t -> 'c t -> f:('a -> 'b -> 'c -> 'd) -> 'd tval all : 'a t list -> 'a list tval all_unit : unit t list -> unit t
module Applicative_infix : Base__.Applicative_intf.Applicative_infix with type 'a t := 'a tinclude Invariant.S1 with type 'a t := 'a t
val invariant : 'a Base__.Invariant_intf.inv -> 'a t Base__.Invariant_intf.inv
include 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 tval return : 'a -> 'a treturn vreturns the (trivial) computation that returns v.
val is_ok : _ t -> boolval is_error : _ t -> boolval try_with : ?backtrace:bool -> (unit -> 'a) -> 'a ttry_with fcatches exceptions thrown byfand returns them in theResult.tas anError.t.try_with_joinis liketry_with, except thatfcan throw exceptions or return anErrordirectly, 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 tval ok : 'ok t -> 'ok optionok treturnsNoneiftis anError, and otherwise returns the contents of theOkconstructor.
val ok_exn : 'a t -> 'aok_exn tthrows an exception iftis anError, and otherwise returns the contents of theOkconstructor.
val of_exn : ?backtrace:[ `Get | `This of string ] -> exn -> _ tof_exn ?backtrace exnisError (Error.of_exn ?backtrace exn).
val of_exn_result : ?backtrace:[ `Get | `This of string ] -> ('a, exn) Result.t -> 'a tof_exn_result ?backtrace (Ok a) = Ok aof_exn_result ?backtrace (Error exn) = of_exn ?backtrace exn
val error : ?strict:unit -> string -> 'a -> ('a -> Sexp.t) -> _ terroris 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 ais lazily computed when the info is converted to a sexp. So, ifais mutated in the time between the call tocreateand the sexp conversion, those mutations will be reflected in the sexp. Use~strict:()to forcesexp_of_a ato be computed immediately.
val error_s : Sexp.t -> _ tval error_string : string -> _ terror_string messageisError (Error.of_string message).
val errorf : ('a, unit, string, _ t) Stdlib.format4 -> 'aerrorf format arg1 arg2 ...isError (sprintf format arg1 arg2 ...). Note that it calculates the string eagerly, so when performance matters you may want to useerrorinstead.
val tag : 'a t -> tag:string -> 'a ttag t ~tagisResult.map_error t ~f:(Error.tag ~tag).tag_argis similar.
val tag_s : 'a t -> tag:Sexp.t -> 'a tval tag_arg : 'a t -> string -> 'b -> ('b -> Sexp.t) -> 'a tval 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.
val map : 'a t -> f:('a -> 'b) -> 'b tval iter : 'a t -> f:('a -> unit) -> unitval iter_error : _ t -> f:(Error.t -> unit) -> unitval combine_errors : 'a t list -> 'a list tcombine_errors tsreturnsOkif every element intsisOk, else it returnsErrorwith 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 tcombine_errors_unit tsreturnsOkif every element intsisOk (), else it returnsErrorwith all the errors ints, likecombine_errors.
val filter_ok_at_least_one : 'a t list -> 'a list tfilter_ok_at_least_one tsreturns all values intsthat areOkif there is at least one, otherwise it returns the same error ascombine_errors ts.