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

Safe HaskellSafe-Inferred
LanguageHaskell2010

Tubes.Core

Synopsis

Documentation

type Tube a b m r = FreeT (TubeF a b) m r Source

A Tube is the free monad transformer arising from TubeF.

newtype TubeF a b k Source

TubeF is the union of unary functions and binary products into a single type, here defined with a Boehm-Berarducci encoding.

Rather than using a normal ADT, which would certainly make the code a bit easier to read and write, a value of this type is actually a control flow mechanism accepting two continuations and choosing one or the other.

Client code should never actually have to deal with this.

Constructors

TubeF 

Fields

runT :: forall r. ((a -> k) -> r) -> ((b, k) -> r) -> r
 

Instances

Functor (TubeF a b) 

type Source b m r = forall x. Tube x b m r Source

A computation which only yields and never awaits

type Sink a m r = forall x. Tube a x m r Source

A computation which only awaits and never yields

type Action m r = forall x. Tube x x m r Source

A computation which neither yields nor awaits

run :: FreeT f m a -> m (FreeF f a (FreeT f m a)) Source

run is shorter than runFreeT and who knows, maybe it'll change some day

await :: Monad m => Tube a b m a Source

Command to wait for a new value upstream

yield :: Monad m => b -> Tube a b m () Source

Command to send a value downstream

yieldF :: b -> k -> TubeF a b k Source

Constructor for source computations

awaitF :: (a -> k) -> TubeF a b k Source

Constructor for sink computations

liftT :: (MonadTrans t, Monad m) => FreeT f m a -> t m (FreeF f a (FreeT f m a)) Source

This performs a neat trick: a Tube with a return type a will be turned into a new Tube containing the underlying TubeF value.

In this way the >< and >- functions can replace the () return value with a continuation and recursively traverse the computation until a final result is reached.

each :: (Monad m, Foldable t) => t b -> Tube a b m () Source

Convert a list to a Source

for :: Monad m => Tube a b m r -> (b -> Tube a c m s) -> Tube a c m r Source

Enumerate yielded values into a continuation, creating a new Source

(><) :: Monad m => Tube a b m r -> Tube b c m r -> Tube a c m r infixl 3 Source

Compose two tasks in a pull-based stream

(>-) :: Monad m => Tube a b m r -> (b -> Tube b c m r) -> Tube a c m r Source

Connect a task to a continuation yielding another task; see ><

(~>) :: Monad m => Tube a b m r -> (b -> Tube a c m s) -> Tube a c m r Source

Infix version of for