Module Lwt_result

Contents

Instructions: Use this module in your project

In the IDE (CLion, Visual Studio Code, Xcode, etc.) you use for your DkSDK project:

  1. Add the following to your project's dependencies/CMakeLists.txt:

    Copy
    DkSDKProject_DeclareAvailable(lwt
        CONSTRAINT "= 5.6.1"
        FINDLIBS lwt lwt.unix)
    DkSDKProject_MakeAvailable(lwt)
  2. Add the Findlib::lwt library to any desired targets in src/*/CMakeLists.txt:

    Copy
    target_link_libraries(YourPackage_YourLibraryName
         # ... existing libraries, if any ...
         Findlib::lwt)
  3. Click your IDE's Build button

Not using DkSDK?

FIRST, do one or all of the following:

  1. Run:

    Copy
    opam install lwt.5.6.1
  2. Edit your dune-project and add:

    Copy
    (package
      (name YourExistingPackage)
      (depends
      ; ... existing dependenices ...
      (lwt (>= 5.6.1))))

    Then run:

    Copy
    dune build *.opam # if this fails, run: dune build
  3. Edit your <package>.opam file and add:

    Copy
    depends: [
      # ... existing dependencies ...
      "lwt" {>= "5.6.1"}
    ]

    Then run:

    Copy
    opam install . --deps-only

FINALLY, add the lwt library to any desired (library)and/or (executable) targets in your **/dune files:

Copy
(library
  (name YourLibrary)
  ; ... existing library options ...
  (libraries
    ; ... existing libraries ...
    lwt))

(executable
  (name YourExecutable)
  ; ... existing executable options ...
  (libraries
    ; ... existing libraries ...
    lwt))

This module provides helpers for values of type ('a, 'b) result Lwt.t. The module is experimental and may change in the future.

type ``(+'a, +'b) t`` = ``('a, 'b)`` result Lwt.t
valreturn :'a -> ``('a, _)`` t
valfail :'b -> ``(_, 'b)`` t
val lift : ``('a, 'b)`` result -> ``('a, 'b)`` t
valok :'a Lwt.t -> ``('a, _)`` t
valerror :'b Lwt.t -> ``(_, 'b)`` t
  • since 5.6.0
valcatch :'a Lwt.t -> ``('a, exn)`` t

catch x behaves like return y if x evaluates to y, and like fail e if x raises e

val get_exn : ``('a, exn)`` t -> 'a Lwt.t

get_exn is the opposite of catch: it unwraps the result type, returning the value in case of success, calls Lwt.fail in case of error.

val map : ``('a -> 'b)`` -> ``('a, 'e)`` t -> ``('b, 'e)`` t
val map_error : ``('e1 -> 'e2)`` -> ``('a, 'e1)`` t -> ``('a, 'e2)`` t
  • since 5.6.0
val bind : ``('a, 'e)`` t -> ``('a -> ``('b, 'e)`` t)`` -> ``('b, 'e)`` t
val bind_error : ``('a, 'e1)`` t -> ``('e1 -> ``('a, 'e2)`` t)`` -> ``('a, 'e2)`` t
  • since 5.6.0
val bind_lwt : ``('a, 'e)`` t -> ``('a -> 'b Lwt.t)`` -> ``('b, 'e)`` t
val bind_lwt_error : ``('a, 'e1)`` t -> ``('e1 -> 'e2 Lwt.t)`` -> ``('a, 'e2)`` t
  • since 5.6.0
val bind_result : ``('a, 'e)`` t -> ``('a -> ``('b, 'e)`` result)`` -> ``('b, 'e)`` t
val both : ``('a, 'e)`` t -> ``('b, 'e)`` t -> ``('a*'b, 'e)`` t

Lwt.both p_1 p_2 returns a promise that is pending until both promises p_1 and p_2 become resolved. If only p_1 is Error e, the promise is resolved with Error e, If only p_2 is Error e, the promise is resolved with Error e, If both p_1 and p_2 resolve with Error _, the promise is resolved with the error that occurred first.

val iter : ``('a ->``unitLwt.t)`` -> ``('a, 'e)`` t ->``unitLwt.t

iter f r is f v if r is a promise resolved with Ok v, and Lwt.return_unit otherwise.

  • since Lwt 5.6.0
val iter_error : ``('e ->``unitLwt.t)`` -> ``('a, 'e)`` t ->``unitLwt.t

iter_error f r is f v if r is a promise resolved with Error v, and Lwt.return_unit otherwise.

  • since Lwt 5.6.0
module Infix:sig...end
module Let_syntax:sig...end
module Syntax:sig...end

include module type of Infix

val (>|=) : ``('a, 'e)`` t -> ``('a -> 'b)`` -> ``('b, 'e)`` t
val (>>=) : ``('a, 'e)`` t -> ``('a -> ``('b, 'e)`` t)`` -> ``('b, 'e)`` t

Deprecated

val map_err : ``('e1 -> 'e2)`` -> ``('a, 'e1)`` t -> ``('a, 'e2)`` t
  • deprecated

    Alias to map_error since 5.6.0.

val bind_lwt_err : ``('a, 'e1)`` t -> ``('e1 -> 'e2 Lwt.t)`` -> ``('a, 'e2)`` t
  • deprecated

    Alias to bind_lwt_error since 5.6.0.