Consumer-1.2: A monad and monad transformer for consuming streams

Control.Monad.Consumer

Contents

Description

A monad for consuming streams - I believe this is basically just a specialized version of the State monad.

Synopsis

Consumer Monad

newtype Consumer c a Source

Constructors

Consumer ([c] -> (a, [c])) 

runConsumer :: [c] -> Consumer c a -> (a, [c])Source

Execute a stateful computation, as a result we get the result of the computation, and the final state.

evalConsumer :: [c] -> Consumer c a -> aSource

Execute a stateful computation, ignoring the final state.

execConsumer :: [c] -> Consumer c a -> [c]Source

Execute a stateful computation, just for the side effect.

class Monad m => MonadConsumer m c | m -> c whereSource

Methods

nextSource

Arguments

:: Monad m' 
=> m (m' c)

return next element from stream

peekSource

Arguments

:: Monad m' 
=> m (m' c)

peek at next element, but leave it in the stream

pokeSource

Arguments

:: c 
-> m c

push and element onto the beginning on the stream

Instances

Consumer Monad Transformer

newtype ConsumerT c m a Source

Constructors

ConsumerT 

Fields

runConsumerT :: [c] -> m (a, [c])
 

Instances