package mechaml

  1. Overview
  2. Docs

Module Agent.MonadSource

Sourcetype 'a m = t -> (t * 'a) Lwt.t
Sourceval bind : 'a m -> ('a -> 'b m) -> 'b m
Sourceval return : 'a -> 'a m
Sourceval return_from_lwt : 'a Lwt.t -> 'a m
Sourceval map : ('a -> 'b) -> 'a m -> 'b m
Sourceval run : t -> 'a m -> t * 'a

Wrappers of Lwt's fail functions

Sourceval fail : exn -> 'a m
Sourceval fail_with : string -> 'a m

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

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

The Infix module defines operators for common bind operations

Sourcemodule Syntax : sig ... end

The Syntax module implements the monadic operators provided by OCaml 4.08

Sourcemodule List : sig ... end

The List module wraps the functions of the Lwt_list module inside the Agent monad. Functions suffixed with _s chain the actions sequentially, passing around the updated agent from an action to the next one. The functions suffixed with _m do everything in parallel, using a copy of the initial state in every thread and returning this same original state. The latter can be useful to retrieve a bunch of resources in batch where the updated state is not of interest (e.g download images)

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

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

Wrap the type of functions operating on the agent such as Agent.cookie_jar or Agent.set_cookie_jar to be 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 through Lwt.return

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

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

Innovation. Community. Security.