scc-0.4: Streaming component combinatorsSource codeContentsIndex
Control.Concurrent.SCC.Types
Contents
Types
Type classes
Constructors
Utility functions
Description
This module defines various Control.Concurrent.SCC.Coroutine.Coroutine types that operate on Sink and Source values. The simplest of the bunch are Consumer and Producer types, which respectively operate on a single source or sink. A Transducer has access both to a Source to read from and a Sink to write into. Finally, a Splitter reads from a single source and writes all input into two sinks of the same type, signalling interesting input boundaries by writing into the third sink.
Synopsis
newtype Performer m r = Performer {
perform :: m r
}
type OpenConsumer m a d x r = AncestorFunctor a d => Source m a x -> Coroutine d m r
newtype Consumer m x r = Consumer {
consume :: forall a d. OpenConsumer m a d x r
}
type OpenProducer m a d x r = AncestorFunctor a d => Sink m a x -> Coroutine d m r
newtype Producer m x r = Producer {
produce :: forall a d. OpenProducer m a d x r
}
type OpenTransducer m a1 a2 d x y = (AncestorFunctor a1 d, AncestorFunctor a2 d) => Source m a1 x -> Sink m a2 y -> Coroutine d m [x]
newtype Transducer m x y = Transducer {
transduce :: forall a1 a2 d. OpenTransducer m a1 a2 d x y
}
type OpenSplitter m a1 a2 a3 a4 d x b = (AncestorFunctor a1 d, AncestorFunctor a2 d, AncestorFunctor a3 d, AncestorFunctor a4 d) => Source m a1 x -> Sink m a2 x -> Sink m a3 x -> Sink m a4 b -> Coroutine d m [x]
newtype Splitter m x b = Splitter {
split :: forall a1 a2 a3 a4 d. OpenSplitter m a1 a2 a3 a4 d x b
}
data Boundary y
= Start y
| End y
| Point y
data Markup y x
= Content x
| Markup (Boundary y)
type Parser m x b = Transducer m x (Markup b x)
class Branching c m x r | c -> m x where
combineBranches :: (forall d. Bool -> (forall a d'. AncestorFunctor d d' => OpenConsumer m a d' x r) -> (forall a d'. AncestorFunctor d d' => OpenConsumer m a d' x r) -> forall a. OpenConsumer m a d x r) -> Bool -> c -> c -> c
isolateConsumer :: forall m x r. Monad m => (forall d. Functor d => Source m d x -> Coroutine d m r) -> Consumer m x r
isolateProducer :: forall m x r. Monad m => (forall d. Functor d => Sink m d x -> Coroutine d m r) -> Producer m x r
isolateTransducer :: forall m x y. Monad m => (forall d. Functor d => Source m d x -> Sink m d y -> Coroutine d m [x]) -> Transducer m x y
isolateSplitter :: forall m x b. Monad m => (forall d. Functor d => Source m d x -> Sink m d x -> Sink m d x -> Sink m d b -> Coroutine d m [x]) -> Splitter m x b
oneToOneTransducer :: Monad m => (x -> y) -> Transducer m x y
statelessTransducer :: Monad m => (x -> [y]) -> Transducer m x y
foldingTransducer :: Monad m => (s -> x -> s) -> s -> (s -> y) -> Transducer m x y
statefulTransducer :: Monad m => (state -> x -> (state, [y])) -> state -> Transducer m x y
statelessSplitter :: Monad m => (x -> Bool) -> Splitter m x b
statefulSplitter :: Monad m => (state -> x -> (state, Bool)) -> state -> Splitter m x ()
splitToConsumers :: (Functor d, Monad m, d1 ~ SinkFunctor d x, AncestorFunctor a (SinkFunctor (SinkFunctor d1 x) b)) => Splitter m x b -> Source m a x -> (Source m (SourceFunctor d x) x -> Coroutine (SourceFunctor d x) m r1) -> (Source m (SourceFunctor d1 x) x -> Coroutine (SourceFunctor d1 x) m r2) -> (Source m (SourceFunctor (SinkFunctor d1 x) b) b -> Coroutine (SourceFunctor (SinkFunctor d1 x) b) m r3) -> Coroutine d m ([x], r1, r2, r3)
splitInputToConsumers :: forall m a d d1 x b. (ParallelizableMonad m, d1 ~ SinkFunctor d x, AncestorFunctor a d) => Bool -> Splitter m x b -> Source m a x -> (Source m (SourceFunctor d1 x) x -> Coroutine (SourceFunctor d1 x) m [x]) -> (Source m (SourceFunctor d x) x -> Coroutine (SourceFunctor d x) m [x]) -> Coroutine d m [x]
pipePS :: forall m a a1 a2 x r1 r2. (ParallelizableMonad m, Functor a, a1 ~ SinkFunctor a x, a2 ~ SourceFunctor a x) => Bool -> (Sink m a1 x -> Coroutine a1 m r1) -> (Source m a2 x -> Coroutine a2 m r2) -> Coroutine a m (r1, r2)
Types
newtype Performer m r Source
A component that performs a computation with no inputs nor outputs.
Constructors
Performer
perform :: m r
show/hide Instances
ParallelizableMonad m => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ())
ParallelizableMonad m => JoinableComponentPair TransducerType (PerformerType r) TransducerType m [x] [y] (Transducer m x y) (Performer m r) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (PerformerType r) TransducerType TransducerType m [x] [y] (Performer m r) (Transducer m x y) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (PerformerType r1) (PerformerType r2) (PerformerType r2) m () () (Performer m r1) (Performer m r2) (Performer m r2)
ParallelizableMonad m => JoinableComponentPair (PerformerType r1) (ProducerType r2) (ProducerType r2) m () [x] (Performer m r1) (Producer m x r2) (Producer m x r2)
ParallelizableMonad m => JoinableComponentPair (ProducerType r1) (PerformerType r2) (ProducerType r2) m () [x] (Producer m x r1) (Performer m r2) (Producer m x r2)
ParallelizableMonad m => JoinableComponentPair (PerformerType r1) (ConsumerType r2) (ConsumerType r2) m [x] () (Performer m r1) (Consumer m x r2) (Consumer m x r2)
ParallelizableMonad m => JoinableComponentPair (ConsumerType r1) (PerformerType r2) (ConsumerType r2) m [x] () (Consumer m x r1) (Performer m r2) (Consumer m x r2)
(AnyListOrUnit x, AnyListOrUnit y) => CompatibleSignature (Performer m r) (PerformerType r) m x y
(AnyListOrUnit x, AnyListOrUnit y) => CompatibleSignature (Performer m r) (PerformerType r) m x y
type OpenConsumer m a d x r = AncestorFunctor a d => Source m a x -> Coroutine d m rSource
newtype Consumer m x r Source
A component that consumes values from a Source.
Constructors
Consumer
consume :: forall a d. OpenConsumer m a d x r
show/hide Instances
ParallelizableMonad m => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ())
ParallelizableMonad m => PipeableComponentPair m y (Transducer m x y) (Consumer m y r) (Consumer m x r)
ParallelizableMonad m => JoinableComponentPair TransducerType (ConsumerType ()) TransducerType m [x] [y] (Transducer m x y) (Consumer m x ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ConsumerType ()) TransducerType TransducerType m [x] [y] (Consumer m x ()) (Transducer m x y) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ProducerType ()) (ConsumerType ()) TransducerType m [x] [y] (Producer m y ()) (Consumer m x ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ConsumerType ()) (ProducerType ()) TransducerType m [x] [y] (Consumer m x ()) (Producer m y ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (PerformerType r1) (ConsumerType r2) (ConsumerType r2) m [x] () (Performer m r1) (Consumer m x r2) (Consumer m x r2)
ParallelizableMonad m => JoinableComponentPair (ConsumerType r1) (PerformerType r2) (ConsumerType r2) m [x] () (Consumer m x r1) (Performer m r2) (Consumer m x r2)
ParallelizableMonad m => JoinableComponentPair (ConsumerType ()) (ConsumerType ()) (ConsumerType ()) m [x] () (Consumer m x ()) (Consumer m x ()) (Consumer m x ())
Monad m => Branching (Consumer m x r) m x r
Monad m => Branching (Consumer m x ()) m x [x]
AnyListOrUnit y => CompatibleSignature (Consumer m x r) (ConsumerType r) m [x] y
AnyListOrUnit y => CompatibleSignature (Consumer m x r) (ConsumerType r) m [x] y
type OpenProducer m a d x r = AncestorFunctor a d => Sink m a x -> Coroutine d m rSource
newtype Producer m x r Source
A component that produces values and puts them into a Sink.
Constructors
Producer
produce :: forall a d. OpenProducer m a d x r
show/hide Instances
ParallelizableMonad m => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ())
ParallelizableMonad m => PipeableComponentPair m x (Producer m x r) (Transducer m x y) (Producer m y r)
ParallelizableMonad m => JoinableComponentPair TransducerType (ProducerType ()) TransducerType m [x] [y] (Transducer m x y) (Producer m y ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ProducerType ()) TransducerType TransducerType m [x] [y] (Producer m y ()) (Transducer m x y) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ProducerType ()) (ConsumerType ()) TransducerType m [x] [y] (Producer m y ()) (Consumer m x ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ConsumerType ()) (ProducerType ()) TransducerType m [x] [y] (Consumer m x ()) (Producer m y ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (PerformerType r1) (ProducerType r2) (ProducerType r2) m () [x] (Performer m r1) (Producer m x r2) (Producer m x r2)
ParallelizableMonad m => JoinableComponentPair (ProducerType r1) (PerformerType r2) (ProducerType r2) m () [x] (Producer m x r1) (Performer m r2) (Producer m x r2)
Monad m => JoinableComponentPair (ProducerType r1) (ProducerType r2) (ProducerType r2) m () [x] (Producer m x r1) (Producer m x r2) (Producer m x r2)
AnyListOrUnit y => CompatibleSignature (Producer m x r) (ProducerType r) m y [x]
AnyListOrUnit y => CompatibleSignature (Producer m x r) (ProducerType r) m y [x]
type OpenTransducer m a1 a2 d x y = (AncestorFunctor a1 d, AncestorFunctor a2 d) => Source m a1 x -> Sink m a2 y -> Coroutine d m [x]Source
newtype Transducer m x y Source
The Transducer type represents computations that transform a data stream. Execution of transduce must continue consuming the given Source and feeding the Sink as long both can be resumed. If the sink dies first, transduce should return the list of all values it has consumed from the source but hasn't managed to process and write into the sink.
Constructors
Transducer
transduce :: forall a1 a2 d. OpenTransducer m a1 a2 d x y
show/hide Instances
ParallelizableMonad m => JoinableComponentPair TransducerType TransducerType TransducerType m [x] [y] (Transducer m x y) (Transducer m x y) (Transducer m x y)
ParallelizableMonad m => PipeableComponentPair m y (Transducer m x y) (Transducer m y z) (Transducer m x z)
ParallelizableMonad m => PipeableComponentPair m x (Producer m x r) (Transducer m x y) (Producer m y r)
ParallelizableMonad m => PipeableComponentPair m y (Transducer m x y) (Consumer m y r) (Consumer m x r)
ParallelizableMonad m => JoinableComponentPair TransducerType (PerformerType r) TransducerType m [x] [y] (Transducer m x y) (Performer m r) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair TransducerType (ProducerType ()) TransducerType m [x] [y] (Transducer m x y) (Producer m y ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair TransducerType (ConsumerType ()) TransducerType m [x] [y] (Transducer m x y) (Consumer m x ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (PerformerType r) TransducerType TransducerType m [x] [y] (Performer m r) (Transducer m x y) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ProducerType ()) TransducerType TransducerType m [x] [y] (Producer m y ()) (Transducer m x y) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ConsumerType ()) TransducerType TransducerType m [x] [y] (Consumer m x ()) (Transducer m x y) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ProducerType ()) (ConsumerType ()) TransducerType m [x] [y] (Producer m y ()) (Consumer m x ()) (Transducer m x y)
ParallelizableMonad m => JoinableComponentPair (ConsumerType ()) (ProducerType ()) TransducerType m [x] [y] (Consumer m x ()) (Producer m y ()) (Transducer m x y)
Monad m => Branching (Transducer m x y) m x [x]
CompatibleSignature (Transducer m x y) TransducerType m [x] [y]
CompatibleSignature (Transducer m x y) TransducerType m [x] [y]
type OpenSplitter m a1 a2 a3 a4 d x b = (AncestorFunctor a1 d, AncestorFunctor a2 d, AncestorFunctor a3 d, AncestorFunctor a4 d) => Source m a1 x -> Sink m a2 x -> Sink m a3 x -> Sink m a4 b -> Coroutine d m [x]Source
newtype Splitter m x b Source

The SplitterComponent type represents computations that distribute the input stream acording to some criteria. A splitter should distribute only the original input data, and feed it into the sinks in the same order it has been read from the source. Furthermore, the input source should be entirely consumed and fed into the first two sinks. The third sink can be used to supply extra information at arbitrary points in the input. If any of the sinks dies before all data is fed to them, split should return the list of all values it has consumed from the source but hasn't managed to write into the sinks.

A splitter can be used in two ways: as a predicate to determine which portions of its input stream satisfy a certain property, or as a chunker to divide the input stream into chunks. In the former case, the predicate is considered true for exactly those parts of the input that are written to its true sink. In the latter case, a chunk is a contiguous section of the input stream that is written exclusively to one sink, either true or false. Anything written to the third sink also terminates the chunk.

Constructors
Splitter
split :: forall a1 a2 a3 a4 d. OpenSplitter m a1 a2 a3 a4 d x b
show/hide Instances
data Boundary y Source
A Markup value is produced to mark either a Start and End of a region of data, or an arbitrary Point in data. A Point is semantically equivalent to a Start immediately followed by End. The Content constructor wraps the actual data.
Constructors
Start y
End y
Point y
show/hide Instances
data Markup y x Source
Constructors
Content x
Markup (Boundary y)
show/hide Instances
Functor (Markup y)
(Eq y, Eq x) => Eq (Markup y x)
Show y => Show (Markup y Char)
type Parser m x b = Transducer m x (Markup b x)Source
Type classes
class Branching c m x r | c -> m x whereSource
Branching is a type class representing all types that can act as consumers, namely Consumer, Transducer, and Splitter.
Methods
combineBranches :: (forall d. Bool -> (forall a d'. AncestorFunctor d d' => OpenConsumer m a d' x r) -> (forall a d'. AncestorFunctor d d' => OpenConsumer m a d' x r) -> forall a. OpenConsumer m a d x r) -> Bool -> c -> c -> cSource
combineBranches is used to combine two values of Branch class into one, using the given Consumer binary combinator.
show/hide Instances
Monad m => Branching (Consumer m x r) m x r
ParallelizableMonad m => Branching (Splitter m x b) m x [x]
Monad m => Branching (Transducer m x y) m x [x]
Monad m => Branching (Consumer m x ()) m x [x]
Constructors
isolateConsumer :: forall m x r. Monad m => (forall d. Functor d => Source m d x -> Coroutine d m r) -> Consumer m x rSource
Creates a proper Consumer from a function that is, but can't be proven to be, an OpenConsumer.
isolateProducer :: forall m x r. Monad m => (forall d. Functor d => Sink m d x -> Coroutine d m r) -> Producer m x rSource
Creates a proper Producer from a function that is, but can't be proven to be, an OpenProducer.
isolateTransducer :: forall m x y. Monad m => (forall d. Functor d => Source m d x -> Sink m d y -> Coroutine d m [x]) -> Transducer m x ySource
Creates a proper Transducer from a function that is, but can't be proven to be, an OpenTransducer.
isolateSplitter :: forall m x b. Monad m => (forall d. Functor d => Source m d x -> Sink m d x -> Sink m d x -> Sink m d b -> Coroutine d m [x]) -> Splitter m x bSource
Creates a proper Splitter from a function that is, but can't be proven to be, an OpenSplitter.
oneToOneTransducer :: Monad m => (x -> y) -> Transducer m x ySource
Function oneToOneTransducer takes a function that maps one input value to one output value each, and lifts it into a Transducer.
statelessTransducer :: Monad m => (x -> [y]) -> Transducer m x ySource
Function statelessTransducer takes a function that maps one input value into a list of output values, and lifts it into a Transducer.
foldingTransducer :: Monad m => (s -> x -> s) -> s -> (s -> y) -> Transducer m x ySource
Function foldingTransducer creates a stateful transducer that produces only one output value after consuming the entire input. Similar to Data.List.foldl
statefulTransducer :: Monad m => (state -> x -> (state, [y])) -> state -> Transducer m x ySource
Function statefulTransducer constructs a Transducer from a state-transition function and the initial state. The transition function may produce arbitrary output at any transition step.
statelessSplitter :: Monad m => (x -> Bool) -> Splitter m x bSource
Function statelessSplitter takes a function that assigns a Boolean value to each input item and lifts it into a Splitter.
statefulSplitter :: Monad m => (state -> x -> (state, Bool)) -> state -> Splitter m x ()Source
Function statefulSplitter takes a state-converting function that also assigns a Boolean value to each input item and lifts it into a Splitter.
Utility functions
splitToConsumers :: (Functor d, Monad m, d1 ~ SinkFunctor d x, AncestorFunctor a (SinkFunctor (SinkFunctor d1 x) b)) => Splitter m x b -> Source m a x -> (Source m (SourceFunctor d x) x -> Coroutine (SourceFunctor d x) m r1) -> (Source m (SourceFunctor d1 x) x -> Coroutine (SourceFunctor d1 x) m r2) -> (Source m (SourceFunctor (SinkFunctor d1 x) b) b -> Coroutine (SourceFunctor (SinkFunctor d1 x) b) m r3) -> Coroutine d m ([x], r1, r2, r3)Source
Given a Splitter, a Source, and three consumer functions, splitToConsumers runs the splitter on the source and feeds the splitter's outputs to its true, false, and edge sinks, respectively, to the three consumers.
splitInputToConsumers :: forall m a d d1 x b. (ParallelizableMonad m, d1 ~ SinkFunctor d x, AncestorFunctor a d) => Bool -> Splitter m x b -> Source m a x -> (Source m (SourceFunctor d1 x) x -> Coroutine (SourceFunctor d1 x) m [x]) -> (Source m (SourceFunctor d x) x -> Coroutine (SourceFunctor d x) m [x]) -> Coroutine d m [x]Source
Given a Splitter, a Source, and two consumer functions, splitInputToConsumers runs the splitter on the source and feeds the splitter's true and false outputs, respectively, to the two consumers.
pipePS :: forall m a a1 a2 x r1 r2. (ParallelizableMonad m, Functor a, a1 ~ SinkFunctor a x, a2 ~ SourceFunctor a x) => Bool -> (Sink m a1 x -> Coroutine a1 m r1) -> (Source m a2 x -> Coroutine a2 m r2) -> Coroutine a m (r1, r2)Source
The pipePS function acts either as pipeP or as pipe, depending on the argument parallel.
Produced by Haddock version 2.6.0