machines-0.2.3: Networked stream transducers

PortabilityRank 2 Types, GADTs
Stabilityprovisional
MaintainerEdward Kmett <ekmett@gmail.com>
Safe HaskellNone

Data.Machine.Process

Contents

Description

 

Synopsis

Processes

type Process a b = Machine (Is a) bSource

A Process a b is a stream transducer that can consume values of type a from its input, and produce values of type b for its output.

type ProcessT m a b = MachineT m (Is a) bSource

A ProcessT m a b is a stream transducer that can consume values of type a from its input, and produce values of type b and has side-effects in the Monad m.

class Automaton k whereSource

An Automaton is can be automatically lifted into a Process

Methods

auto :: k a b -> Process a bSource

process :: Monad m => (forall a. k a -> i -> a) -> MachineT m k o -> ProcessT m i oSource

Convert a machine into a process, with a little bit of help.

 process L :: Process a c -> Tee a b c
 process R :: Process b c -> Tee a b c
 process id :: Process a b -> Process a b

Common Processes

(<~) :: Monad m => ProcessT m b c -> MachineT m k b -> MachineT m k cSource

Build a new Machine by adding a Process to the output of an old Machine

 (<~) :: Process b c -> Process a b -> Process a c
 (<~) :: Process c d -> Tee a b c -> Tee a b d
 (<~) :: Process b c -> Machine k b -> Machine k c

(~>) :: Monad m => MachineT m k b -> ProcessT m b c -> MachineT m k cSource

Flipped (<~).

echo :: Process a aSource

The trivial Process that simply repeats each input it receives.

supply :: Monad m => [a] -> ProcessT m a b -> ProcessT m a bSource

Feed a Process some input.

prepended :: Foldable f => f a -> Process a aSource

A Process that prepends the elements of a Foldable onto its input, then repeats its input from there.

filtered :: (a -> Bool) -> Process a aSource

A Process that only passes through inputs that match a predicate.

dropping :: Int -> Process a aSource

A Process that drops the first n, then repeats the rest.

taking :: Int -> Process a aSource

A Process that passes through the first n elements from its input then stops

droppingWhile :: (a -> Bool) -> Process a aSource

A Process that drops elements while a predicate holds

takingWhile :: (a -> Bool) -> Process a aSource

A Process that passes through elements until a predicate ceases to hold, then stops

buffered :: Int -> Process a [a]Source

Chunk up the input into n element lists.

Avoids returning empty lists and deals with the truncation of the last group.