machines
Copyright(C) 2012 Edward Kmett Rúnar Bjarnason Paul Chiusano
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <[email protected]>
Stabilityprovisional
PortabilityRank-2 Types, GADTs
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.Machine.Tee

Contents

Description

 
Synopsis

Tees

type Tee a b c = Machine (T a b) c Source #

A Machine that can read from two input stream in a deterministic manner.

type TeeT (m :: Type -> Type) a b c = MachineT m (T a b) c Source #

A Machine that can read from two input stream in a deterministic manner with monadic side-effects.

data T a b c where Source #

The input descriptor for a Tee or TeeT

Constructors

L :: forall a b. T a b a 
R :: forall a b. T a b b 

tee :: forall (m :: Type -> Type) a a' b b' c. Monad m => ProcessT m a a' -> ProcessT m b b' -> TeeT m a' b' c -> TeeT m a b c Source #

Compose a pair of pipes onto the front of a Tee.

Examples:

>>> import Data.Machine.Source
>>> run $ tee (source [1..]) (source ['a'..'c']) zipping
[(1,'a'),(2,'b'),(3,'c')]

teeT :: forall (m :: Type -> Type) a b c (k :: Type -> Type). Monad m => TeeT m a b c -> MachineT m k a -> MachineT m k b -> MachineT m k c Source #

`teeT mt ma mb` Use a Tee to interleave or combine the outputs of ma and mb.

The resulting machine will draw from a single source.

Examples:

>>> import Data.Machine.Source
>>> run $ teeT zipping echo echo <~ source [1..5]
[(1,2),(3,4)]

addL :: forall (m :: Type -> Type) a b c d. Monad m => ProcessT m a b -> TeeT m b c d -> TeeT m a c d Source #

Precompose a pipe onto the left input of a tee.

addR :: forall (m :: Type -> Type) b c a d. Monad m => ProcessT m b c -> TeeT m a c d -> TeeT m a b d Source #

Precompose a pipe onto the right input of a tee.

capL :: forall (m :: Type -> Type) a b c. Monad m => SourceT m a -> TeeT m a b c -> ProcessT m b c Source #

Tie off one input of a tee by connecting it to a known source.

capR :: forall (m :: Type -> Type) b a c. Monad m => SourceT m b -> TeeT m a b c -> ProcessT m a c Source #

Tie off one input of a tee by connecting it to a known source.

capT :: forall (m :: Type -> Type) a b c. Monad m => SourceT m a -> SourceT m b -> TeeT m a b c -> SourceT m c Source #

Tie off both inputs to a tee by connecting them to known sources. This is recommended over capping each side separately, as it is far more efficient.

zipWithT :: forall a b c (m :: Type -> Type). (a -> b -> c) -> PlanT (T a b) c m () Source #

wait for both the left and the right sides of a T and then merge them with f.

zipWith :: (a -> b -> c) -> Tee a b c Source #

Zip together two inputs, then apply the given function, halting as soon as either input is exhausted. This implementation reads from the left, then the right

zipping :: forall a b (m :: Type -> Type). Monad m => MachineT m (T a b) (a, b) Source #

Zip together two inputs, halting as soon as either input is exhausted.