morley-client-0.1.2: Client to interact with the Tezos blockchain
Safe HaskellNone
LanguageHaskell2010

Morley.Util.Batching

Synopsis

Documentation

data BatchingM i o e a Source #

Records operations to be executed in batch.

Chronologically, this works in 3 steps:

  • Form the list of input items i;
  • Perform the batch operation;
  • Parse output items o into result a, maybe producing error e.

However in code we usually want steps 1 and 3 to be grouped and step 2 to be delayed - BatchingM facilitates this separation.

Note that BatchingM is fundamentally not a monad, rather just an applicative, because within a batch you cannot use result of one operation in another operation.

Instances

Instances details
Functor (BatchingM i o e) Source # 
Instance details

Defined in Morley.Util.Batching

Methods

fmap :: (a -> b) -> BatchingM i o e a -> BatchingM i o e b #

(<$) :: a -> BatchingM i o e b -> BatchingM i o e a #

Applicative (BatchingM i o e) Source # 
Instance details

Defined in Morley.Util.Batching

Methods

pure :: a -> BatchingM i o e a #

(<*>) :: BatchingM i o e (a -> b) -> BatchingM i o e a -> BatchingM i o e b #

liftA2 :: (a -> b -> c) -> BatchingM i o e a -> BatchingM i o e b -> BatchingM i o e c #

(*>) :: BatchingM i o e a -> BatchingM i o e b -> BatchingM i o e b #

(<*) :: BatchingM i o e a -> BatchingM i o e b -> BatchingM i o e a #

runBatching :: Functor m => ([i] -> m (r, [o])) -> BatchingM i o e a -> m (r, Either (BatchingError e) a) Source #

Run recorded operations sequence using the given batch executor.

unsafeRunBatching :: (Functor m, Buildable e) => ([i] -> m (r, [o])) -> BatchingM i o e a -> m (r, a) Source #

Similar to runBatching, for cases when the given batch executor is guaranteed to return the output respective to the provided input.

submitThenParse :: i -> (o -> Either e a) -> BatchingM i o e a infix 1 Source #

This is the basic primitive for all actions in BatchingM.

It records that given input item should be put to batch, and once operation is actually performed, the result should be parsed with given method.

data BatchingError e Source #

Errors that can occur during batching, usually because the underlying function that performs batch operation returns output that does not match the provided input.

Constructors

InsufficientOutput

The function that executes the batch returned less elements in output than were provided at input.

ExtraOutput

The function that executes the batch returned more elements in output than were provided at input.

UnexpectedElement e

User-provided parsing method failed. Usually this means that output does not correspond to provided input.

Instances

Instances details
Buildable e => Buildable (BatchingError e) Source # 
Instance details

Defined in Morley.Util.Batching

Methods

build :: BatchingError e -> Builder #