package middleware
Library
Module
Module type
Parameter
Class
Class type
A "middleware" function is one which runs before, after, and possibly instead of another function.
Middleware can be composed, in order to create a chain of wrapping invocations.
Note that a middleware function can not be called on its own. It is required to be "terminated" by a conventional function.
module type MONAD = sig ... end
Minimal monad definition required by a Middleware.
module type MONAD2 = sig ... end
Monads of two type parameters.
module Monads : sig ... end
Some common monads.
Creates a Middleware module, providing effects with the given Monad.
Creates a Middleware module, providing effects with the given two-parameter Monad.
Middleware backed by the identity monad.
include sig ... end
module Diverter : sig ... end
val stop : 'output Monads.Identity.t -> ('a, 'b, 'output) Diverter.t
stop x
creates a Stop
Diverter
with the return value x
.
val continue :
'next_input ->
('next_output -> 'output Monads.Identity.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:
Stop
s, and returns a resultContinue
s by allowing the next middleware functiong
to run- After
g
runs, control returns tof
, wheref
can respond tog
's result and change its own return value.
val terminate :
('ai, 'bi, 'bo, 'ao) t ->
('bi -> 'bo Monads.Identity.t) ->
'ai ->
'ao Monads.Identity.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
.
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