Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module Make.Lwt_option_syntax
Syntax module for Lwt+Option. This is intended to be opened locally in functions which use Lwt and option for control-flow. Within the scope of this module, the code can include binding operators, leading to a let-style syntax.
See also Lwt, Option.
val return : 'a->'a optionLwt.t
return x is Lwt.return (Some x).
val return_unit : unit optionLwt.t
return_unit is Lwt.return (Some ()) .
val return_nil : 'a list optionLwt.t
return_nil is Lwt.return (Some []) .
val return_true : bool optionLwt.t
return_true is Lwt.return (Some true) .
val return_false : bool optionLwt.t
return_false is Lwt.return (Some false) .
Note that we do not provide return_some nor return_none. Both of these functions are possible but somewhat confusing and rarely useful in practice. If you need to carry options within a LwtOption-monad computation (yielding values of the type 'a option option Lwt.t), you need to do so by hand: return (Some …) and return (None).
val fail : 'a optionLwt.t
fail is Lwt.return None.
val (let*) : 'a optionLwt.t->('a->'b optionLwt.t)->'b optionLwt.t
let* is a binding operator alias for Lwt.bind mixed with Option.bind.
val (and*) : 'a optionLwt.t->'b optionLwt.t->('a * 'b) optionLwt.t
and* is a binding operator alias for both.
val (let+) : 'a optionLwt.t->('a->'b)->'b optionLwt.t
let+ is a binding operator alias for Lwt.map mixed with Option.map.
val (and+) : 'a optionLwt.t->'b optionLwt.t->('a * 'b) optionLwt.t
and* is a binding operator alias for both.
The following values are for mixing expressions that are Lwt-only or Option-only within the Lwt option monad. Note that there are fundamental differences between option and Lwt.t: the former can be simply matched on (i.e., it is possible to get out of the monad at any point) whereas the latter can only be bound on (i.e., it is not possible to get out of the monad). In addition, the former is for aborting computations on failures (which in this case means that no value can be produced) whereas the latter is for waiting before continuing.
Still, from a syntax point-of-view, both are handled the same way: with a specialised binding operator.
val (let*!) : 'aLwt.t->('a->'bLwt.t)->'bLwt.t
let*! is for binding Lwt-only expressions into the Lwt option combined monad.
let open Lwt_option_syntax in
let* x = … in
let*! y = … in
return (x + y)
val (let*?) : 'a option->('a->'b optionLwt.t)->'b optionLwt.t
let*? is for binding the value from Option-only expressions into the Lwt option combined monad.
let open Lwt_option_syntax in
let* x = … in
let*? y = … in
…
val both : 'a optionLwt.t->'b optionLwt.t->('a * 'b) optionLwt.t
both is the joining of two concurrent optional non-unit values.