package tezos-lwt-result-stdlib
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=296bb5674bc6050afe6330326fbdd0dfc2255d414bfd6b79cc7666ac6b39316d
sha512=c061cd300a9410300851158d77bf8e56ca3c568b0b1161b38305e5b2efdcd9c746d391f832fdb2826f9a1d6babce10a9b764a4b04f5df42699f7314b9863123a
doc/bare_structs/Bare_structs/Result/index.html
Module Bare_structs.Result
Source
include Bare_sigs.Result.S
val bind_error :
('a, 'e) Stdlib.result ->
('e -> ('a, 'f) Stdlib.result) ->
('a, 'f) Stdlib.result
val bind_s :
('a, 'e) Stdlib.result ->
('a -> ('b, 'e) Stdlib.result Lwt.t) ->
('b, 'e) Stdlib.result Lwt.t
val bind_error_s :
('a, 'e) Stdlib.result ->
('e -> ('a, 'f) Stdlib.result Lwt.t) ->
('a, 'f) Stdlib.result Lwt.t
val map_e :
('a -> ('b, 'e) Stdlib.result) ->
('a, 'e) Stdlib.result ->
('b, 'e) Stdlib.result
val map_es :
('a -> ('b, 'e) Stdlib.result Lwt.t) ->
('a, 'e) Stdlib.result ->
('b, 'e) Stdlib.result Lwt.t
val map_error_e :
('e -> ('a, 'f) Stdlib.result) ->
('a, 'e) Stdlib.result ->
('a, 'f) Stdlib.result
val map_error_es :
('e -> ('a, 'f) Stdlib.result Lwt.t) ->
('a, 'e) Stdlib.result ->
('a, 'f) Stdlib.result Lwt.t
val equal :
ok:('a -> 'a -> bool) ->
error:('e -> 'e -> bool) ->
('a, 'e) Stdlib.result ->
('a, 'e) Stdlib.result ->
bool
val compare :
ok:('a -> 'a -> int) ->
error:('e -> 'e -> int) ->
('a, 'e) Stdlib.result ->
('a, 'e) Stdlib.result ->
int
catch f
is try Ok (f ()) with e -> Error e
: it is Ok x
if f ()
evaluates to x
, and it is Error e
if f ()
raises e
.
See WithExceptions.S.Result.to_exn
for a converse function.
If catch_only
is set, then only exceptions e
such that catch_only e
is true
are caught.
Whether catch_only
is set or not, this function never catches non-deterministic runtime exceptions of OCaml such as Stack_overflow
and Out_of_memory
.
val catch_f :
?catch_only:(exn -> bool) ->
(unit -> 'a) ->
(exn -> 'e) ->
('a, 'e) Stdlib.result
catch_f f handler
is equivalent to map_error (catch f) handler
. In other words, it catches exceptions in f ()
and either returns the value in an Ok
or passes the exception to handler
for the Error
.
No attempt is made to catch the exceptions raised by handler
.
catch_only
has the same use as with catch
. The same restriction on catching non-deterministic runtime exceptions applies.
val catch_ef :
?catch_only:(exn -> bool) ->
(unit -> ('a, 'error) Stdlib.result) ->
(exn -> 'error) ->
('a, 'error) Stdlib.result
catch_ef f handler
is equivalent to join @@ map_error (catch f) handler
. In other words, it catches exceptions in f ()
and either returns the value as is or passes the exception to handler
for the Error
. The handler must return an error of the same type as that carried by f ()
.
No attempt is made to catch the exceptions raised by handler
.
catch_only
has the same use as with catch
. The same restriction on catching non-deterministic runtime exceptions applies.
val catch_s :
?catch_only:(exn -> bool) ->
(unit -> 'a Lwt.t) ->
('a, exn) Stdlib.result Lwt.t
catch_s
is catch
but for Lwt promises. Specifically, catch_s f
returns a promise that resolves to Ok x
if and when f ()
resolves to x
, or to Error exc
if and when f ()
is rejected with exc
.
If catch_only
is set, then only exceptions e
such that catch_only e
is true
are caught.
Whether catch_only
is set or not, this function never catches non-deterministic runtime exceptions of OCaml such as Stack_overflow
and Out_of_memory
.
We do not provide catch_s_f
because (a) the suffix becomes confusing, (b) it's not used, (c) it is not obvious whether we want the handler to be within Lwt (gives more flexibility) or not (gives more guarantee about the timeliness of learning about rejections). We will revisit this if a needs for it arises.