batching-0.1.0.0: An Applicative Functor deferring actions to run in a batch later.
Safe HaskellNone
LanguageHaskell2010

Control.Batching

Description

An Applicative for deferring "requests" to handle them all in bulk.

Synopsis

Documentation

data Batching rq rs a Source #

The bulk request-response Applicative.

A value of type Batching rq rs a describes a computation that gathers some number of rq request values, expects the same number of rs response values, and ultimately returns an a result value derived from the responses.

This can be used to apply an offline resource allocation algorithm to code written as if allocation requests were satisfied incrementally.

This synergizes well with -XApplicativeDo, which allows using do-notation for this type, as long as requests do not depend on earlier responses.

Instances

Instances details
Functor (Batching rq rs) Source # 
Instance details

Defined in Control.Batching

Methods

fmap :: (a -> b) -> Batching rq rs a -> Batching rq rs b #

(<$) :: a -> Batching rq rs b -> Batching rq rs a #

Applicative (Batching rq rs) Source # 
Instance details

Defined in Control.Batching

Methods

pure :: a -> Batching rq rs a #

(<*>) :: Batching rq rs (a -> b) -> Batching rq rs a -> Batching rq rs b #

liftA2 :: (a -> b -> c) -> Batching rq rs a -> Batching rq rs b -> Batching rq rs c #

(*>) :: Batching rq rs a -> Batching rq rs b -> Batching rq rs b #

(<*) :: Batching rq rs a -> Batching rq rs b -> Batching rq rs a #

request :: rq -> Batching rq rs rs Source #

Issue one request and retrieve its response.

batchRequest :: forall t rq rs. Traversable t => t rq -> Batching rq rs (t rs) Source #

Issue a Traversable of requests and retrieve their responses.

runBatching :: Functor f => (forall n. Vec n rq -> f (Vec n rs)) -> Batching rq rs a -> f a Source #

Given an allocator function in any Functor, run a Batching computation.

runBatching_ :: (forall n. Vec n rq -> Vec n rs) -> Batching rq rs a -> a Source #

Like runBatching, but without a Functor (or implicitly in Identity).