tubes-0.2.1.0: Effectful, iteratee-inspired stream processing based on a free monad.

Safe HaskellSafe-Inferred
LanguageHaskell2010

Tubes.Pump

Synopsis

Documentation

type Pump a b = CofreeT (PumpF a b) Source

A Pump is the dual to a Tube: where a Tube is a computation manipulating a stream of values, a Pump can be situated on either end of a tube to both insert values when requested and handle any yielded results.

This module is subject to change before I upload `0.2.0.0` to Hackage.

data PumpF a b k Source

Constructors

PumpF 

Fields

recvF :: (a, k)
 
sendF :: b -> k
 

Instances

Functor (PumpF a b) 

pump :: Comonad w => w a -> (w a -> (b, w a)) -> (w a -> c -> w a) -> Pump b c w a Source

Creates a Pump for a Tube using a comonadic seed value, a function to give it more data upon request, and a function to handle any yielded results. . Values received from the Tube may be altered and sent back into the tube, hence this mechanism does act like something of a pump.

recv :: Comonad w => Pump a b w r -> (a, Pump a b w r) Source

Pull a value from a Pump, along with the rest of the Pump.

send :: Comonad w => Pump a b w r -> b -> Pump a b w r Source

Send a value into a Pump, effectively re-seeding the stream.

runPump :: (Comonad w, Monad m) => (x -> y -> r) -> Pump a b w x -> Tube a b m y -> m r Source

Given a suitably matching Tube and Pump, you can use the latter to execute the former.