package tezos-lwt-result-stdlib
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=6b33e0549574c89a63538c94ce5555dd141e3c0fb5d934abff07d702fa3244d2
sha512=681a197baabec6e2f806871d43490382243207518f8fcf932741cd314d8717e46db2b6a5adc222f8726083a5dd911083b4931b7e878ab815f8f1a32763d1bf93
doc/bare_sigs/Bare_sigs/Monad/index.html
Module Bare_sigs.Monad
Lwt, result, and Lwt-result monad operators
This module provides the necessary functions and operators to use Lwt, result and Lwt-result as a monad.
Basics
The three, tiered monads have each their full set of operators:
The Lwt monad:
Lwt.return
for return,Lwt.bind
or(>>=)
for bind, andLwt.map
or(>|=)
for map.
The result monad:
Result.ok
orok
for return,Result.bind
or(>>?)
for bind, andResult.map
(>|?)
for map.
In addition, Result.error
or error
is for failures within the result monad.
The Lwt-result monad:
return
orLwt.return_ok
for return,(>>=?)
for bind, and(>|=?)
for map.
In addition, fail
is for the failure within the Lwt-result combined monad.
Note that future improvements are planned to (a) make those more uniform, (b) allow the opening of selected infix operators only, and (c) provide let*
-binds.
Preallocated values
The module also provides preallocated values for the common types:
unit_s
(respunit_e
) (respunit_es
) isLwt.return ()
(respOk ()
) (respLwt.return (Ok ())
),none_s
(respnone_e
) (respnone_es
) isLwt.return None
(respOk None
) (respLwt.return (Ok None)
),- etc. (see full inventory below)
Note that some of these values are also available in their dedicated modules. E.g., none_*
are available in Option
.
Joins
The join_p
function takes a list of promises ps
and returns a single promise p
that resolves with ()
when all the promises of ps
have resolved.
The all_p
function takes a list of promises ps
and returns a single promise p
that resolves when all the promises of ps
have resolved. The value p
resolves to is the list of values the promises of ps
resolve to. The order is preserved.
The both_p
function takes two promises p1
and p2
and returns a single promise p
that resolves when both promises p1
and p2
have resolved. The value p
resolves to is the tuple of values the promises p1
and p2
resolve to.
Note that like all _p
functions, these functions have a best-effort semantic: they only resolve once all the underlying promises have resolved.
The _e
variants are equivalent for the result monad: the final result is Ok
if all the underlying results are Ok
.
The _es
variants are equivalent for the Lwt-result monad: the final promise resolves to Ok
if all the underlying promise resolve to Ok
.
module type S = sig ... end
lwt monad