package sugar

  1. Overview
  2. Docs

Module Make.ForSource

Create a new result module based on the current one, but wrapped around a monad.

Parameters

Signature

include S.Promise with type error := error with type 'a monad := 'a UserMonad.t
Sourcetype 'a value = ('a, error) Result.result

An alias for Pervasives.result that can only work with errors of your project.

Sourcetype 'a result = 'a value UserMonad.t

This type describes a result monad inside a project.

For example, if the concrete module is built on top of Lwt, a value of type unit result will be translated as (unit, error) Pervasives.result Lwt.t.

Sourceval (>>=) : 'a result -> ('a -> 'b result) -> 'b result

This combinator is also called bind.

It can be used to chain sequential operations with the current monad. If the computation in the left failed, the operator will propagate the error, skipping the function completely.

Sourceval bind : 'a result -> ('a -> 'b result) -> 'b result

Similar to S.Result.bind

Sourceval bind_unless : 'a result -> (error -> 'a result) -> 'a result

Similar to S.Result.bind_unless

Sourceval map : 'a result -> ('a -> 'b) -> 'b result

Similar to S.Result.map

Sourceval return : 'a -> 'a result

Similar to S.Result.return

Sourceval throw : error -> 'a result

Similar to S.Result.throw

Sourcemodule Infix : sig ... end
Sourceval unwrap : 'a value UserMonad.t -> 'a UserMonad.t

Unwraps the successful value as a normal value in the threading monad. If the value is not successful, it will raise an Invalid_arg exception.

Sourceval unwrap_or : (error -> 'a UserMonad.t) -> 'a value UserMonad.t -> 'a UserMonad.t

Unwraps the successful value as a value in the threading monad. Different from unwrap, you can assign an error handler to be executed if the computation failed.

Sourceval expect : 'a value UserMonad.t -> string -> 'a UserMonad.t

Extracts a successful value from an computation, or raises and Invalid_arg exception with a customized error message.

Sourcemodule NoExceptions : S.Promise with type error := error and type 'a monad := 'a UserMonad.t

Disable exception handling. Open this module with you don't want to catch exceptions.