package mechaml

  1. Overview
  2. Docs
type 'a m = t -> (t * 'a) Lwt.t
val bind : 'a m -> ('a -> 'b m) -> 'b m
val return : 'a -> 'a m
val return_from_lwt : 'a Lwt.t -> 'a m
val map : ('a -> 'b) -> 'a m -> 'b m
val run : t -> 'a m -> t * 'a
val fail : exn -> 'a m

Wrappers of Lwt's fail functions

val fail_with : string -> 'a m

Wrappers of Lwt.catch and Lwt.try_bind inside this monad

val catch : (unit -> 'a m) -> (exn -> 'a m) -> 'a m
val try_bind : (unit -> 'a m) -> ('a -> 'b m) -> (exn -> 'b m) -> 'b m
module Infix : sig ... end

The Infix module defines operators for common bind operations

module List : sig ... end

The List module mainly wrap the Lwt_list one in the Agent monad. Functions suffixed with _s chains the actions sequentially, passing around the updated agent to the next one. The _m ones do everything in parallel, sending a copy of the initial state to every threads and returning this same unupdated state. The latter can be useful to retrive a bunch of ressources in batch where the updated state is not of interest (e.g images)

get the current state of the agent, or set a new one

val get : t m
val set : t -> unit m

Wrap the type of functions operating on the agent such as Agent.cookie_jar or Agent.set_cookie_jar to usable inside the monad. For example, the first one go from Agent.t -> Cookiejar.t to Agent.t -> (Agent.t * Cookiejar.t) Lwt.t by just returning the agent unmodified together with the current cookie jar and wrap the result in Lwt.return

Note that the redefined functions have the same name as their counterpart, and thus will shadow or can be shadowed by them.

val save_content : string -> string -> unit m
val client_headers : Cohttp.Header.t m
val set_client_headers : Cohttp.Header.t -> unit m
val add_client_header : string -> string -> unit m
val remove_client_header : string -> unit m
val set_max_redirect : int -> unit m
OCaml

Innovation. Community. Security.