Module Lwt_result
Explicit error handling
- since
- 2.6.0
type (+'a, +'b) t
= ('a, 'b) Result.result Lwt.t
val return : 'a -> ('a, _) t
val fail : 'b -> (_, 'b) t
val lift : ('a, 'b) Result.result -> ('a, 'b) t
val ok : 'a Lwt.t -> ('a, _) t
val catch : 'a Lwt.t -> ('a, exn) t
catch x
behaves likereturn y
ifx
evaluates toy
, and likefail e
ifx
raisese
val get_exn : ('a, exn) t -> 'a Lwt.t
get_exn
is the opposite ofcatch
: it unwraps the result type, returning the value in case of success, callsLwt.fail
in case of error.
val map : ('a -> 'b) -> ('a, 'e) t -> ('b, 'e) t
val map_err : ('e1 -> 'e2) -> ('a, 'e1) t -> ('a, 'e2) t
val bind : ('a, 'e) t -> ('a -> ('b, 'e) t) -> ('b, 'e) t
val bind_lwt : ('a, 'e) t -> ('a -> 'b Lwt.t) -> ('b, 'e) t
val bind_lwt_err : ('a, 'e1) t -> ('e1 -> 'e2 Lwt.t) -> ('a, 'e2) t
val bind_result : ('a, 'e) t -> ('a -> ('b, 'e) Result.result) -> ('b, 'e) t
val both : ('a, 'e) t -> ('b, 'e) t -> ('a * 'b, 'e) t
Lwt.both p_1 p_2
returns a promise that is pending until both promisesp_1
andp_2
become resolved. If onlyp_1
isError e
, the promise is resolved withError e
, If onlyp_2
isError e
, the promise is resolved withError e
, If bothp_1
andp_2
resolve withError _
, the promise is resolved with the error that occurred first.
module Infix : sig ... end
module Syntax : sig ... end