Module Base.Or_errorSource
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.tSerialization and comparison of an Error force the error's lazy message.
val hash_fold_t :
('a : value_or_null). (Ppx_hash_lib.Std.Hash.state ->
'a ->
Ppx_hash_lib.Std.Hash.state) ->
Ppx_hash_lib.Std.Hash.state ->
'a t ->
Ppx_hash_lib.Std.Hash.stateval sexp_of_t__stack :
('a : value_or_null). ('a @ local -> Sexplib0.Sexp.t @ local) ->
'a t @ local ->
Sexplib0.Sexp.t @ localval t_sexp_grammar :
('a : value_or_null). 'a Sexplib0.Sexp_grammar.t ->
'a t Sexplib0.Sexp_grammar.t @@ portableApplicative 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__'value_or_null_mod_maybe_null'__local
with type ('a : value_or_null) t := 'a t
val apply :
('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'p 'q.
('a -> 'b) t ->
'a t ->
'b tApplies the functions in one t to the values in another. Well-behaved applicatives satisfy these "laws", using <*> as infix apply:
return Fn.id <*> tis equivalent totreturn Fn.compose <*> tf <*> tg <*> txis equivalent totf <*> (tg <*> tx)return f <*> return xis equivalent toreturn (f x)tf <*> return xis equivalent toreturn (fun f -> f x) <*> tf
val both :
('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'p 'q.
'a t ->
'b t ->
('a * 'b) tCombines values in two ts as tuples. Using <*> as infix apply, equivalent to return (fun a b -> a, b) <*> ta <*> tb.
val map2 :
('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) ('c : value_or_null mod maybe_null) 'p 'q.
'a t ->
'b t ->
f:('a -> ('b -> 'c) @ local) @ local ->
'c tCombines the contents of two ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb.
val map3 :
('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) ('c : value_or_null mod maybe_null) ('d : value_or_null mod maybe_null) 'p 'q.
'a t ->
'b t ->
'c t ->
f:('a -> ('b -> ('c -> 'd) @ local) @ local) @ local ->
'd tCombines the contents of three ts. Using <*> as infix apply, equivalent to return f <*> ta <*> tb <*> tc.
include Invariant.S1 with type 'a t := 'a t
include Monad.S__'value_or_null_mod_maybe_null'__local
with type ('a : value_or_null) t := 'a t
Combines nested t into just one layer. Equivalent to bind t ~f:Fn.id.
Ignores contained values of t. Equivalent to map t ~f:ignore.
Combines a list of t.
Combines a list of t whose contents are unimportant.
val (>>=) :
('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'i 'j 'k 'p 'q.
'a t ->
('a -> 'b t) @ local ->
'b tInfix bind.
val (>>|) :
('a : value_or_null mod maybe_null) ('b : value_or_null mod maybe_null) 'i 'j 'p 'q.
'a t ->
('a -> 'b) @ local ->
'b tInfix map.
val try_with :
('a : value_or_null). ?backtrace:bool ->
(unit -> 'a) @ local once ->
'a t @@ portabletry_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).
ok t returns None if t is an Error, and otherwise returns the contents of the Ok constructor.
ok_or_null t returns Null if t is an Error, and otherwise returns the contents of the Ok constructor wrapped in This.
ok_exn t throws an exception if t is an Error, and otherwise returns the contents of the Ok constructor.
val of_exn :
('a : value_or_null). ?backtrace:[ `Get | `This of string ] ->
exn ->
'a t @@ portableof_exn ?backtrace exn is Error (Error.of_exn ?backtrace exn).
val of_exn_result :
('a : value_or_null). ?backtrace:[ `Get | `This of string ] ->
('a, exn) Result.t ->
'a t @@ portableof_exn_result ?backtrace (Ok a) = Ok a
of_exn_result ?backtrace (Error exn) = of_exn ?backtrace exn
of_option t returns Ok 'a if t is Some 'a, and otherwise returns the supplied error as Error error
val of_option_lazy :
('a : value_or_null). 'a option ->
error:Error.t Lazy.t ->
'a t @@ portableCalls of_option ~error:(Error.of_lazy_t error).
val of_option_lazy_sexp :
('a : value_or_null). 'a option ->
error:Sexp.t Lazy.t ->
'a t @@ portableCalls of_option ~error:(Error.of_lazy_sexp error).
val of_option_lazy_string :
('a : value_or_null). 'a option ->
error:string Lazy.t ->
'a t @@ portableCalls of_option ~error:(Error.of_lazy error).
of_or_null t ~error returns Ok 'a if t is This 'a, and otherwise returns the supplied error as Error error.
Calls of_or_null ~error:(Error.of_lazy_t error).
Calls of_or_null ~error:(Error.of_lazy_sexp error).
Calls of_or_null ~error:(Error.of_lazy error).
val error :
('a : value_or_null mod uncontended) ('b : value_or_null). ?here:
Lexing.position ->
?strict:unit ->
string ->
'a ->
('a -> Sexp.t) ->
'b t @@ portableerror 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.
error_string message is Error (Error.of_string message).
errorf 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 errorf_portable :
'a ('b : value_or_null). ('a, unit, string, unit -> 'b t @ portable) format4 ->
'a @@ portableerrorf_portable format arg1 arg2 ... () is like errorf format arg1 arg2 ... but constructing a portable error.
tag t ~tag is Result.map_error t ~f:(Error.tag ~tag).
tag_s is like tag with a sexp tag.
tag_lazy is like tag with a lazy tag.
tag_s_lazy is like tag with a lazy sexp tag.
val tag_arg :
('a : value_or_null) ('b : value_or_null). 'a t ->
string ->
'b ->
('b -> Sexp.t) ->
'a t @@ portabletag_arg is like tag, with a tag that has a sexpable argument.
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.
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 ts 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. Returns a bespoke error when passed an empty list.
find_ok ts returns the first value in ts that is Ok, otherwise it returns the same error as combine_errors ts.
val find_map_ok :
('a : value_or_null) ('b : value_or_null). 'a list ->
f:('a -> 'b t) @ local ->
'b t @@ portablefind_map_ok l ~f returns the first value in l for which f returns Ok, otherwise it returns the same error as combine_errors (List.map l ~f). Returns a bespoke error when passed an empty list.