Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

- type Tube a b = FreeT (TubeF a b)
- newtype TubeF a b k = TubeF {
- runT :: forall r. ((a -> k) -> r) -> ((b, k) -> r) -> r

- type Source b m r = forall x. Tube x b m r
- type Sink a m r = forall x. Tube a x m r
- run :: FreeT f m a -> m (FreeF f a (FreeT f m a))
- await :: Monad m => Tube a b m a
- yield :: Monad m => b -> Tube a b m ()
- each :: (Monad m, Foldable t) => t b -> Tube a b m ()
- for :: Monad m => Tube a b m r -> (b -> Tube a c m s) -> Tube a c m r
- (><) :: Monad m => Tube a b m r -> Tube b c m r -> Tube a c m r
- (>-) :: Monad m => Tube a b m r -> (b -> Tube b c m r) -> Tube a c m r
- (~>) :: Monad m => Tube a b m r -> (b -> Tube a c m s) -> Tube a c m r
- (-<) :: Monad m => a -> Sink a m b -> Sink a m b
- (|>) :: Monad m => Source b m () -> Sink (Maybe b) m s -> Sink (Maybe b) m s
- yieldF :: b -> k -> TubeF a b k
- awaitF :: (a -> k) -> TubeF a b k
- liftT :: (MonadTrans t, Monad m) => FreeT f m a -> t m (FreeF f a (FreeT f m a))

# Basic definitions

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

A `Tube`

is a computation which can

`yield`

an intermediate value downstream and suspend execution; and`await`

a value from upstream, deferring execution until it is received.

Moreover, individual `Tube`

s may be freely composed into larger ones, so long
as their types match. Thus, one may write small, reusable building blocks and
construct efficient stream process pipelines.

Since a much better engineered, more popular, and decidedly more mature library already uses the term "pipes" I have opted instead to think of my work as a series of tubes.

`TubeF`

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

This type is equivalent to the following:

data TubeF a b k = Await (a -> k) -- :: (a -> k) -> TubeF a b k | Yield (b , k) -- :: (b , k) -> TubeF a b k

The type signatures for the two value constructors should bear a strong
resemblance to the actual type signature of `runT`

. Instead of encoding
tubes as structures which build up when composed, a `TubeF`

is a control
flow mechanism which picks one of two provided continuations.

People using this library should never have to contend with these details but it is worth mentioning.

# Type aliases

# Core commands

# Control mechanisms

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

Compose two tubes into a new tube.

(>-) :: 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 `><`