package octez-libs

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Module Bare_structs.ResultSource

include Bare_sigs.Result.S
Sourcetype ('a, 'e) t = ('a, 'e) Stdlib.result =
  1. | Ok of 'a
  2. | Error of 'e
Sourceval ok : 'a -> ('a, 'e) Stdlib.result
Sourceval ok_s : 'a -> ('a, 'e) Stdlib.result Lwt.t
Sourceval error : 'e -> ('a, 'e) Stdlib.result
Sourceval error_s : 'e -> ('a, 'e) Stdlib.result Lwt.t
Sourceval value : ('a, 'e) Stdlib.result -> default:'a -> 'a
Sourceval value_f : ('a, 'e) Stdlib.result -> default:(unit -> 'a) -> 'a
Sourceval bind : ('a, 'e) Stdlib.result -> ('a -> ('b, 'e) Stdlib.result) -> ('b, 'e) Stdlib.result
Sourceval bind_error : ('a, 'e) Stdlib.result -> ('e -> ('a, 'f) Stdlib.result) -> ('a, 'f) Stdlib.result
Sourceval map : ('a -> 'b) -> ('a, 'e) Stdlib.result -> ('b, 'e) Stdlib.result
Sourceval map_error : ('e -> 'f) -> ('a, 'e) Stdlib.result -> ('a, 'f) Stdlib.result
Sourceval bind_s : ('a, 'e) Stdlib.result -> ('a -> ('b, 'e) Stdlib.result Lwt.t) -> ('b, 'e) Stdlib.result Lwt.t
Sourceval bind_error_s : ('a, 'e) Stdlib.result -> ('e -> ('a, 'f) Stdlib.result Lwt.t) -> ('a, 'f) Stdlib.result Lwt.t
Sourceval join : (('a, 'e) Stdlib.result, 'e) Stdlib.result -> ('a, 'e) Stdlib.result
Sourceval map_e : ('a -> ('b, 'e) Stdlib.result) -> ('a, 'e) Stdlib.result -> ('b, 'e) Stdlib.result
Sourceval map_s : ('a -> 'b Lwt.t) -> ('a, 'e) Stdlib.result -> ('b, 'e) Stdlib.result Lwt.t
Sourceval map_es : ('a -> ('b, 'e) Stdlib.result Lwt.t) -> ('a, 'e) Stdlib.result -> ('b, 'e) Stdlib.result Lwt.t
Sourceval map_error_e : ('e -> ('a, 'f) Stdlib.result) -> ('a, 'e) Stdlib.result -> ('a, 'f) Stdlib.result
Sourceval map_error_s : ('e -> 'f Lwt.t) -> ('a, 'e) Stdlib.result -> ('a, 'f) Stdlib.result Lwt.t
Sourceval map_error_es : ('e -> ('a, 'f) Stdlib.result Lwt.t) -> ('a, 'e) Stdlib.result -> ('a, 'f) Stdlib.result Lwt.t
Sourceval fold : ok:('a -> 'c) -> error:('e -> 'c) -> ('a, 'e) Stdlib.result -> 'c
Sourceval iter : ('a -> unit) -> ('a, 'e) Stdlib.result -> unit
Sourceval iter_s : ('a -> unit Lwt.t) -> ('a, 'e) Stdlib.result -> unit Lwt.t
Sourceval iter_error : ('e -> unit) -> ('a, 'e) Stdlib.result -> unit
Sourceval iter_error_s : ('e -> unit Lwt.t) -> ('a, 'e) Stdlib.result -> unit Lwt.t
Sourceval is_ok : ('a, 'e) Stdlib.result -> bool
Sourceval is_error : ('a, 'e) Stdlib.result -> bool
Sourceval equal : ok:('a -> 'a -> bool) -> error:('e -> 'e -> bool) -> ('a, 'e) Stdlib.result -> ('a, 'e) Stdlib.result -> bool
Sourceval compare : ok:('a -> 'a -> int) -> error:('e -> 'e -> int) -> ('a, 'e) Stdlib.result -> ('a, 'e) Stdlib.result -> int
Sourceval to_option : ('a, 'e) Stdlib.result -> 'a option
Sourceval of_option : error:'e -> 'a option -> ('a, 'e) Stdlib.result
Sourceval to_list : ('a, 'e) Stdlib.result -> 'a list
Sourceval to_seq : ('a, 'e) Stdlib.result -> 'a Stdlib.Seq.t
Sourceval catch : ?catch_only:(exn -> bool) -> (unit -> 'a) -> ('a, exn) Stdlib.result

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.

Sourceval 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.

Sourceval 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.

Sourceval 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.

OCaml

Innovation. Community. Security.