package tezos-error-monad

  1. Overview
  2. Docs
val ok : 'a -> ('a, 'trace) result

Successful result

val ok_unit : (unit, 'trace) result
val ok_none : ('a option, 'trace) result
val ok_some : 'a -> ('a option, 'trace) result
val ok_nil : ('a list, 'trace) result
val ok_true : (bool, 'trace) result
val ok_false : (bool, 'trace) result
val return : 'a -> ('a, 'trace) result Lwt.t

Successful return

val return_unit : (unit, 'trace) result Lwt.t

Successful return of ()

val return_none : ('a option, 'trace) result Lwt.t

Successful return of None

val return_some : 'a -> ('a option, 'trace) result Lwt.t

return_some x is a successful return of Some x

val return_nil : ('a list, 'trace) result Lwt.t

Successful return of []

val return_true : (bool, 'trace) result Lwt.t

Successful return of true

val return_false : (bool, 'trace) result Lwt.t

Successful return of false

val error : 'err -> ('a, 'err Trace.trace) result

Erroneous result

val fail : 'err -> ('a, 'err Trace.trace) result Lwt.t

Erroneous return

Infix operators for monadic binds/maps. All operators follow this naming convention:

  • the first character is >
  • the second character is > for bind and | for map
  • the next character is = for Lwt or ? for Error
  • the next character (if present) is = for Lwt or ? for Error, it is only used for operator that are within both monads.
val (>>=) : 'a Lwt.t -> ('a -> 'b Lwt.t) -> 'b Lwt.t

Lwt's bind reexported. Following Lwt's convention, in this operator and the ones below, = indicate we operate within Lwt.

val (>|=) : 'a Lwt.t -> ('a -> 'b) -> 'b Lwt.t

Lwt's map reexported. The | indicates a map rather than a bind.

val (>>?) : ('a, 'trace) result -> ('a -> ('b, 'trace) result) -> ('b, 'trace) result

Non-Lwt bind operator. In this operator and the ones below, ? indicates that we operate within the error monad.

val (>|?) : ('a, 'trace) result -> ('a -> 'b) -> ('b, 'trace) result

Non-Lwt map operator.

val (>>=?) : ('a, 'trace) result Lwt.t -> ('a -> ('b, 'trace) result Lwt.t) -> ('b, 'trace) result Lwt.t

Combined bind operator. The =? indicates that the operator acts within the combined error-lwt monad.

val (>|=?) : ('a, 'trace) result Lwt.t -> ('a -> 'b) -> ('b, 'trace) result Lwt.t

Combined map operator.

val (>>?=) : ('a, 'trace) result -> ('a -> ('b, 'trace) result Lwt.t) -> ('b, 'trace) result Lwt.t

Injecting bind operator. This is for transitioning from the simple Error monad to the combined Error-Lwt monad.

Note the order of the character: it starts with the error monad marker ? and has the Lwt monad marker later. This hints at the role of the operator to transition into Lwt.

val (>|?=) : ('a, 'trace) result -> ('a -> 'b Lwt.t) -> ('b, 'trace) result Lwt.t

Injecting map operator.

val record_trace : 'err -> ('a, 'err Trace.trace) result -> ('a, 'err Trace.trace) result

Enrich an error report (or do nothing on a successful result) manually

val trace : 'err -> ('b, 'err Trace.trace) result Lwt.t -> ('b, 'err Trace.trace) result Lwt.t

Automatically enrich error reporting on stack rewind

val record_trace_eval : (unit -> ('err, 'err Trace.trace) result) -> ('a, 'err Trace.trace) result -> ('a, 'err Trace.trace) result

Same as record_trace, for unevaluated error

val trace_eval : (unit -> ('err, 'err Trace.trace) result Lwt.t) -> ('b, 'err Trace.trace) result Lwt.t -> ('b, 'err Trace.trace) result Lwt.t

Same as trace, for unevaluated Lwt error

val error_unless : bool -> 'err -> (unit, 'err Trace.trace) result

Error on failed assertion

val error_when : bool -> 'err -> (unit, 'err Trace.trace) result
val fail_unless : bool -> 'err -> (unit, 'err Trace.trace) result Lwt.t

Erroneous return on failed assertion

val fail_when : bool -> 'err -> (unit, 'err Trace.trace) result Lwt.t
val unless : bool -> (unit -> (unit, 'trace) result Lwt.t) -> (unit, 'trace) result Lwt.t
val when_ : bool -> (unit -> (unit, 'trace) result Lwt.t) -> (unit, 'trace) result Lwt.t
val dont_wait : (exn -> unit) -> ('trace -> unit) -> (unit -> (unit, 'trace) result Lwt.t) -> unit

Wrapper around Lwt_utils.dont_wait

val join_p : unit Lwt.t list -> unit Lwt.t

A few aliases for Lwt functions

val all_p : 'a Lwt.t list -> 'a list Lwt.t
val both_p : 'a Lwt.t -> 'b Lwt.t -> ('a * 'b) Lwt.t
val join_e : (unit, 'err Trace.trace) result list -> (unit, 'err Trace.trace) result

Similar functions in the error monad

val all_e : ('a, 'err Trace.trace) result list -> ('a list, 'err Trace.trace) result
val both_e : ('a, 'err Trace.trace) result -> ('b, 'err Trace.trace) result -> ('a * 'b, 'err Trace.trace) result
val join_ep : (unit, 'err Trace.trace) result Lwt.t list -> (unit, 'err Trace.trace) result Lwt.t

Similar functions in the combined monad

val all_ep : ('a, 'err Trace.trace) result Lwt.t list -> ('a list, 'err Trace.trace) result Lwt.t
val both_ep : ('a, 'err Trace.trace) result Lwt.t -> ('b, 'err Trace.trace) result Lwt.t -> ('a * 'b, 'err Trace.trace) result Lwt.t