package middleware

  1. Overview
  2. Docs

Creates a Middleware module, providing effects with the given Monad.

Parameters

module M : MONAD

Signature

module Diverter : sig ... end
val stop : 'output M.t -> (_, _, 'output) Diverter.t

stop x creates a Stop Diverter with the return value x.

val continue : 'next_input -> ('next_output -> 'output M.t) -> ('next_input, 'next_output, 'output) Diverter.t

continue next_input fn creates a Continue diverter, passing next_input to the subsequent Middleware g. fn is applied to the value returned by g.

type ('input, 'next_input, 'next_output, 'output) t = 'input -> ('next_input, 'next_output, 'output) Diverter.t

A function which composes with other Middleware functions. Composed Middleware can respond to the return value of Middleware running later. When a Middleware function f runs, it either:

  • Stops, and returns a result
  • Continues by allowing the next middleware function g to run
  • After g runs, control returns to f, where f can respond to g's result and change its own return value.
val terminate : ('ai, 'bi, 'bo, 'ao) t -> ('bi -> 'bo M.t) -> 'ai -> 'ao M.t

terminate ma fb terminates Middleware ma by providing a function fb which does not delegate. In order to turn a Middleware chain into a function, it must be terminated by a non-delegating function using terminate.

val compose : ('ai, 'bi, 'bo, 'ao) t -> ('bi, 'ci, 'co, 'bo) t -> ('ai, 'ci, 'co, 'ao) t

compose ma mb composes two Middleware functions. When run, ma first runs, giving mb the option to continue later on. Note that a composed Middleware still need to be terminated via terminate to be called.

module Infix : sig ... end
OCaml

Innovation. Community. Security.