package tezos-base

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

Syntax module for Result. This is intended to be opened locally in functions which use result for control-flow. Within the scope of this module, the code can include binding operators, leading to a let-style syntax.

See also Result

val return : 'a -> ('a, 'e) Stdlib.result

return x is Ok x.

val return_unit : (unit, 'e) Stdlib.result

return_unit is Ok ().

val return_none : ('a option, 'e) Stdlib.result

return_none is Ok None.

val return_some : 'a -> ('a option, 'e) Stdlib.result

return_some x is Ok (Some x).

val return_nil : ('a list, 'e) Stdlib.result

return_nil is Ok [].

val return_true : (bool, 'e) Stdlib.result

return_true is Ok true.

val return_false : (bool, 'e) Stdlib.result

return_false is Ok false.

Note that we do not provide return_ok nor return_error. Both of these functions are possible but somewhat confusing and rarely useful in practice. If you need to carry results within a Result-monad computation (yielding to values of the type (('a, 'e) result, 'e) result), you need to do so by hand: return (Ok …) and return (Error …).

val fail : 'e -> ('a, 'e) Stdlib.result

fail e is Error e. It is also an alias for error.

val let* : ('a, 'e) Stdlib.result -> ('a -> ('b, 'e) Stdlib.result) -> ('b, 'e) Stdlib.result

let* is a binding operator alias for Result.bind and >>?.

val let+ : ('a, 'e) Stdlib.result -> ('a -> 'b) -> ('b, 'e) Stdlib.result

let+ is a binding operator alias for Result.map and >|?.

Note that we do not provide and* nor and+. Both of these are possible but their type is unsatisfying because the errors do not compose well. You can use both (below) if need be.

val join : (unit, 'e) Stdlib.result list -> (unit, 'e list) Stdlib.result

join is the joining of success/failure unit values.

val all : ('a, 'e) Stdlib.result list -> ('a list, 'e list) Stdlib.result

all is the joining of success/failure non-unit values.

val both : ('a, 'e) Stdlib.result -> ('b, 'e) Stdlib.result -> ('a * 'b, 'e list) Stdlib.result

both is the joining of two success/failure non-unit values.

OCaml

Innovation. Community. Security.