package tezos-lwt-result-stdlib
Install
    
    dune-project
 Dependency
Authors
Maintainers
Sources
sha256=43723d096307603703a1a89ed1b2eb202b365f5e7824b96b0cbf813b343a6cf7
    
    
  sha512=b2a637f2e965000d3d49ad85277ca24d6cb07a1a7cf2bc69d296d8b03ad78c3eaa8e21e94b9162e62c2e11649cd03bc845b2a3dafe623b91065df69d47dc8e4f
    
    
  doc/index.html
Lwtreslib: an Lwt- and Result-friendly addition/replacement for the Stdlib
The OCaml's Stdlib modules are orthogonal: each define their own datatype and a set of functions operating on this datatype. Result for result, Option for option, List for list, etc. This orthogonality provides a high expressive power for a low lines-of-code count. E.g.,
let fold f init xs =
   List.fold_left
      (fun acc x -> Result.bind acc (fun acc -> f acc x))
      (Result.ok init)
      xsHowever, in code-bases that make heavy uses of some datatypes, a little more integration is welcome. For example, in code bases that use the result type pervasively, the fold function above should be available in a module of list-traversing functions.
Lwtreslib is a library that supplement some of the OCaml's Stdlib modules with a tight integration of Lwt and Result. It focuses on data-structures that can be traversed (iterated, mapped, folded, what have you).
Design principles
- Exception-safety - The functions exported by Lwtreslib do not raise exceptions. These functions may return - optionor- resultto indicate that some error happened during traversal, and they may propagate- result.- (For convenience, the module - WithExceptionsprovides a few exception-raising functions which are convenient in specific contexts.)
- Coverage - As much as it makes sense, for each function - foo, Lwtreslib also provides- foo_e: a variant operating on- result,
- foo_s: a variant operating on- Lwtpromises, sequentially,
- foo_es: a variant operating on- Lwtpromises of results, sequentially,
- foo_p: a variant operating on- Lwtpromises, concurrently, and
- foo_ep: a variant operating on- Lwtpromises of results, concurrently.
 - As mentioned, this is only applied when it makes sense. E.g., some traversals cannot happen concurrently in which case the - _pand- _epare not provided.
- Semantic consistency - Exported functions and values have consistent names that reflect their consistent semantic. For example, all - _eand- _esfunctions have a fail-early semantic wherein the traversal is interrupted as soon as an- Erroroccurs.
API
The Tezos_lwt_result_stdlib library exports a single top-level module Lwtreslib. This module exports Bare for simple traversal functions, and Traced for traversal with automatic composition of errors.
Reading guide
It is recommended to read the entirety of the documentation of the entry-point Lwtreslib module. It contains a high-level overview as well as some details about notable features of the library.