scc-0.8.2.4: Streaming component combinators

Control.Concurrent.SCC.Types

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 Fieldsperform :: m r

Instances

 (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x r) (Consumer m x ()) (Performer m r) Source # Methodscompose :: PairBinder m -> Producer m x r -> Consumer m x () -> Performer m r Source # (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x r) (Performer m r) Source # Methodscompose :: PairBinder m -> Producer m x () -> Consumer m x r -> Performer m r Source # (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ()) Source # Methodscompose :: PairBinder m -> Producer m x () -> Consumer m x () -> Performer m () Source # (AnyListOrUnit x, AnyListOrUnit y) => CompatibleSignature (Performer m r) (PerformerType r) m x y Source #

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

newtype Consumer m x r Source #

A coroutine that consumes values from a Source.

Constructors

 Consumer Fieldsconsume :: 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) Source # Methodscompose :: PairBinder m -> Producer m x r -> Consumer m x () -> Performer m r Source # (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x r) (Performer m r) Source # Methodscompose :: PairBinder m -> Producer m x () -> Consumer m x r -> Performer m r Source # (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ()) Source # Methodscompose :: PairBinder m -> Producer m x () -> Consumer m x () -> Performer m () Source # (Monad m, Monoid x, Monoid y) => PipeableComponentPair m y (Transducer m x y) (Consumer m y r) (Consumer m x r) Source # Methodscompose :: PairBinder m -> Transducer m x y -> Consumer m y r -> Consumer m x r Source # Monad m => Branching (Consumer m x r) m x r Source # MethodscombineBranches :: (forall d. PairBinder m -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m r) -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m r) -> forall a. (AncestorFunctor a d, Monoid x) => Source m a x -> Coroutine d m r) -> PairBinder m -> Consumer m x r -> Consumer m x r -> Consumer m x r Source # AnyListOrUnit y => CompatibleSignature (Consumer m x r) (ConsumerType r) m [x] y Source #

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

newtype Producer m x r Source #

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

Constructors

 Producer Fieldsproduce :: 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) Source # Methodscompose :: PairBinder m -> Producer m x r -> Consumer m x () -> Performer m r Source # (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x r) (Performer m r) Source # Methodscompose :: PairBinder m -> Producer m x () -> Consumer m x r -> Performer m r Source # (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ()) Source # Methodscompose :: PairBinder m -> Producer m x () -> Consumer m x () -> Performer m () Source # (Monad m, Monoid x, Monoid y) => PipeableComponentPair m x (Producer m x r) (Transducer m x y) (Producer m y r) Source # Methodscompose :: PairBinder m -> Producer m x r -> Transducer m x y -> Producer m y r Source # AnyListOrUnit y => CompatibleSignature (Producer m x r) (ProducerType r) m y [x] Source #

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 r Source #

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 Fieldstransduce :: 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) Source # Methodscompose :: PairBinder m -> Transducer m x y -> Transducer m y z -> Transducer m x z Source # (Monad m, Monoid x, Monoid y) => PipeableComponentPair m x (Producer m x r) (Transducer m x y) (Producer m y r) Source # Methodscompose :: PairBinder m -> Producer m x r -> Transducer m x y -> Producer m y r Source # (Monad m, Monoid x, Monoid y) => PipeableComponentPair m y (Transducer m x y) (Consumer m y r) (Consumer m x r) Source # Methodscompose :: PairBinder m -> Transducer m x y -> Consumer m y r -> Consumer m x r Source # Monad m => Branching (Transducer m x y) m x () Source # MethodscombineBranches :: (forall d. PairBinder m -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m ()) -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m ()) -> forall a. (AncestorFunctor a d, Monoid x) => Source m a x -> Coroutine d m ()) -> PairBinder m -> Transducer m x y -> Transducer m x y -> Transducer m x y Source # CompatibleSignature (Transducer m x y) TransducerType m [x] [y] Source #

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 r Source #

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 Fieldssplit :: forall a1 a2 a3 d. OpenSplitter m a1 a2 a3 d x ()

Instances

 Monad m => Branching (Splitter m x) m x () Source # MethodscombineBranches :: (forall d. PairBinder m -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m ()) -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m ()) -> forall a. (AncestorFunctor a d, Monoid x) => Source m a x -> Coroutine d m ()) -> PairBinder m -> Splitter m x -> Splitter m x -> Splitter m x Source #

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

 Source # Methodsfmap :: (a -> b) -> Boundary a -> Boundary b #(<$) :: a -> Boundary b -> Boundary a # Eq y => Eq (Boundary y) Source # Methods(==) :: Boundary y -> Boundary y -> Bool #(/=) :: Boundary y -> Boundary y -> Bool # Show y => Show (Boundary y) Source # MethodsshowsPrec :: Int -> Boundary y -> ShowS #show :: Boundary y -> String #showList :: [Boundary y] -> ShowS # 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  Source # Methodsfmap :: (a -> b) -> Markup y a -> Markup y b #(<$) :: a -> Markup y b -> Markup y a # (Monoid x, Monoid y, Coercible x y) => Coercible [Markup b x] y Source # Methodscoerce :: Monad m => Transducer m [Markup b x] y Source #adaptConsumer :: (Monad m, Monoid [Markup b x], Monoid y) => Consumer m y r -> Consumer m [Markup b x] r Source #adaptProducer :: (Monad m, Monoid [Markup b x], Monoid y) => Producer m [Markup b x] r -> Producer m y r Source # Coercible [x] [y] => Coercible [Markup b x] [y] Source # Methodscoerce :: Monad m => Transducer m [Markup b x] [y] Source #adaptConsumer :: (Monad m, Monoid [Markup b x], Monoid [y]) => Consumer m [y] r -> Consumer m [Markup b x] r Source #adaptProducer :: (Monad m, Monoid [Markup b x], Monoid [y]) => Producer m [Markup b x] r -> Producer m [y] r Source # (Eq y, Eq x) => Eq (Markup y x) Source # Methods(==) :: Markup y x -> Markup y x -> Bool #(/=) :: Markup y x -> Markup y x -> Bool # (Show x, Show y) => Show (Markup y x) Source # MethodsshowsPrec :: Int -> Markup y x -> ShowS #show :: Markup y x -> String #showList :: [Markup y x] -> ShowS #

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 where Source #

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.

Minimal complete definition

compose

Methods

compose :: PairBinder m -> c1 -> c2 -> c3 Source #

Instances

 (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x r) (Consumer m x ()) (Performer m r) Source # Methodscompose :: PairBinder m -> Producer m x r -> Consumer m x () -> Performer m r Source # (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x r) (Performer m r) Source # Methodscompose :: PairBinder m -> Producer m x () -> Consumer m x r -> Performer m r Source # (Monad m, Monoid x) => PipeableComponentPair m x (Producer m x ()) (Consumer m x ()) (Performer m ()) Source # Methodscompose :: PairBinder m -> Producer m x () -> Consumer m x () -> Performer m () Source # (Monad m, Monoid x, Monoid y, Monoid z) => PipeableComponentPair m y (Transducer m x y) (Transducer m y z) (Transducer m x z) Source # Methodscompose :: PairBinder m -> Transducer m x y -> Transducer m y z -> Transducer m x z Source # (Monad m, Monoid x, Monoid y) => PipeableComponentPair m x (Producer m x r) (Transducer m x y) (Producer m y r) Source # Methodscompose :: PairBinder m -> Producer m x r -> Transducer m x y -> Producer m y r Source # (Monad m, Monoid x, Monoid y) => PipeableComponentPair m y (Transducer m x y) (Consumer m y r) (Consumer m x r) Source # Methodscompose :: PairBinder m -> Transducer m x y -> Consumer m y r -> Consumer m x r Source #

class Branching c m x r | c -> m x where Source #

Branching is a type class representing all types that can act as consumers, namely Consumer, Transducer, and Splitter.

Minimal complete definition

combineBranches

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 -> c Source #

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 () Source # MethodscombineBranches :: (forall d. PairBinder m -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m ()) -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m ()) -> forall a. (AncestorFunctor a d, Monoid x) => Source m a x -> Coroutine d m ()) -> PairBinder m -> Splitter m x -> Splitter m x -> Splitter m x Source # Monad m => Branching (Transducer m x y) m x () Source # MethodscombineBranches :: (forall d. PairBinder m -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m ()) -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m ()) -> forall a. (AncestorFunctor a d, Monoid x) => Source m a x -> Coroutine d m ()) -> PairBinder m -> Transducer m x y -> Transducer m x y -> Transducer m x y Source # Monad m => Branching (Consumer m x r) m x r Source # MethodscombineBranches :: (forall d. PairBinder m -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m r) -> (forall a d'. (AncestorFunctor d d', AncestorFunctor a d', Monoid x) => Source m a x -> Coroutine d' m r) -> forall a. (AncestorFunctor a d, Monoid x) => Source m a x -> Coroutine d m r) -> PairBinder m -> Consumer m x r -> Consumer m x r -> Consumer m x r Source #

# 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 r Source #

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 r Source #

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 y Source #

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 x Source #

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 y Source #

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] y Source #

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 y Source #

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] y Source #

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.