scc-0.8: Streaming component combinators

Safe HaskellNone

Control.Concurrent.SCC.Types

Contents

Description

This module defines various 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 of the input, without any modifications, into two sinks of the same type.

Synopsis

Component types

newtype Performer m r Source

A coroutine that has no inputs nor outputs - and therefore may not suspend at all, which means it's not really a coroutine.

Constructors

Performer 

Fields

perform :: m r
 

Instances

(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x r) (Consumer m x ()) (Performer m r) 
(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x r) (Performer m r) 
(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ()) 
(AnyListOrUnit x, AnyListOrUnit y) => CompatibleSignature (Performer m r) (PerformerType r) m x y 

type OpenConsumer m a d x r = (AncestorFunctor a d, Monoid x) => Source m a x -> Coroutine d m rSource

newtype Consumer m x r Source

A coroutine that consumes values from a Source.

Constructors

Consumer 

Fields

consume :: forall a d. OpenConsumer m a d x r
 

Instances

(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x r) (Consumer m x ()) (Performer m r) 
(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x r) (Performer m r) 
(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ()) 
(Monad m, Monoid x, Monoid y) => PipeableComponentPair m y (Transducer m x y) (Consumer m y r) (Consumer m x r) 
Monad m => Branching (Consumer m x r) m x r 
AnyListOrUnit y => CompatibleSignature (Consumer m x r) (ConsumerType r) m [x] y 

type OpenProducer m a d x r = (AncestorFunctor a d, Monoid x) => Sink m a x -> Coroutine d m rSource

newtype Producer m x r Source

A coroutine that produces values and puts them into a Sink.

Constructors

Producer 

Fields

produce :: forall a d. OpenProducer m a d x r
 

Instances

(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x r) (Consumer m x ()) (Performer m r) 
(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x r) (Performer m r) 
(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ()) 
(Monad m, Monoid x, Monoid y) => PipeableComponentPair m x (Producer m x r) (Transducer m x y) (Producer m y r) 
AnyListOrUnit y => CompatibleSignature (Producer m x r) (ProducerType r) m y [x] 

type OpenTransducer m a1 a2 d x y r = (AncestorFunctor a1 d, AncestorFunctor a2 d, Monoid x, Monoid y) => Source m a1 x -> Sink m a2 y -> Coroutine d m rSource

newtype Transducer m x y Source

The Transducer type represents coroutines that transform a data stream. Execution of transduce must continue consuming the given Source and feeding the Sink as long as there is any data in the source.

Constructors

Transducer 

Fields

transduce :: forall a1 a2 d. OpenTransducer m a1 a2 d x y ()
 

Instances

(Monad m, Monoid x, Monoid y, Monoid z) => PipeableComponentPair m y (Transducer m x y) (Transducer m y z) (Transducer m x z) 
(Monad m, Monoid x, Monoid y) => PipeableComponentPair m x (Producer m x r) (Transducer m x y) (Producer m y r) 
(Monad m, Monoid x, Monoid y) => PipeableComponentPair m y (Transducer m x y) (Consumer m y r) (Consumer m x r) 
Monad m => Branching (Transducer m x y) m x () 
CompatibleSignature (Transducer m x y) TransducerType m [x] [y] 

type OpenSplitter m a1 a2 a3 d x r = (AncestorFunctor a1 d, AncestorFunctor a2 d, AncestorFunctor a3 d, Monoid x) => Source m a1 x -> Sink m a2 x -> Sink m a3 x -> Coroutine d m rSource

newtype Splitter m x Source

The Splitter type represents coroutines 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 two 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. A mempty value written to either of the two sinks can also terminate the chunk written to the other sink.

Constructors

Splitter 

Fields

split :: forall a1 a2 a3 d. OpenSplitter m a1 a2 a3 d x ()
 

Instances

Monad m => Branching (Splitter m x) m x () 

data Boundary y Source

A Boundary 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.

Constructors

Start y 
End y 
Point y 

Instances

Functor Boundary 
Eq y => Eq (Boundary y) 
Show y => Show (Boundary y) 

data Markup y x Source

Type of values in a markup-up stream. The Content constructor wraps the actual data.

Constructors

Content x 
Markup (Boundary y) 

Instances

Functor (Markup y) 
(Monoid x, Monoid y, Coercible x y) => Coercible [Markup b x] y 
Coercible [x] [y] => Coercible [Markup b x] [y] 
(Eq y, Eq x) => Eq (Markup y x) 
(Show x, Show y) => Show (Markup y x) 

type Parser m x b = Transducer m x [Markup b x]Source

A parser is a transducer that marks up its input.

class PipeableComponentPair m w c1 c2 c3 | c1 c2 -> c3, c1 c3 -> c2, c2 c3 -> c2, c1 -> m w, c2 -> m w, c3 -> m whereSource

Class PipeableComponentPair applies to any two components that can be combined into a third component with the following properties:

  • The input of the result, if any, becomes the input of the first component.
  • The output produced by the first child component is consumed by the second child component.
  • The result output, if any, is the output of the second component.

Methods

compose :: PairBinder m -> c1 -> c2 -> c3Source

Instances

(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x r) (Consumer m x ()) (Performer m r) 
(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x r) (Performer m r) 
(Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ()) 
(Monad m, Monoid x, Monoid y, Monoid z) => PipeableComponentPair m y (Transducer m x y) (Transducer m y z) (Transducer m x z) 
(Monad m, Monoid x, Monoid y) => PipeableComponentPair m x (Producer m x r) (Transducer m x y) (Producer m y r) 
(Monad m, Monoid x, Monoid y) => PipeableComponentPair m y (Transducer m x y) (Consumer m y r) (Consumer m x r) 

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. PairBinder m -> (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) -> PairBinder m -> c -> c -> cSource

combineBranches is used to combine two values of Branch class into one, using the given Consumer binary combinator.

Instances

Monad m => Branching (Splitter m x) m x () 
Monad m => Branching (Transducer m x y) m x () 
Monad m => Branching (Consumer m x r) m x r 

Component constructors

isolateConsumer :: forall m x r. (Monad m, Monoid x) => (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, Monoid x) => (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, Monoid x) => (forall d. Functor d => Source m d x -> Sink m d y -> Coroutine d m ()) -> 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, Monoid x) => (forall d. Functor d => Source m d x -> Sink m d x -> Sink m d x -> Coroutine d m ()) -> Splitter m xSource

Creates a proper Splitter from a function that is, but can't be proven to be, an OpenSplitter.

oneToOneTransducer :: (Monad m, FactorialMonoid x, Monoid y) => (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.

statelessChunkTransducer :: 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.

statefulTransducer :: (Monad m, MonoidNull y) => (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]Source

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.