Copyright | Copyright (c) 2009-2014, David Sorokin <david.sorokin@gmail.com> |
---|---|

License | BSD3 |

Maintainer | David Sorokin <david.sorokin@gmail.com> |

Stability | experimental |

Safe Haskell | None |

Language | Haskell2010 |

Tested with: GHC 7.8.3

The infinite stream of data in time.

- newtype Stream m a = Cons {}
- emptyStream :: MonadComp m => Stream m a
- mergeStreams :: MonadComp m => Stream m a -> Stream m a -> Stream m a
- mergeQueuedStreams :: (MonadComp m, EnqueueStrategy m s) => s -> Stream m a -> Stream m a -> Stream m a
- mergePriorityStreams :: (MonadComp m, PriorityQueueStrategy m s p) => s -> Stream m (p, a) -> Stream m (p, a) -> Stream m a
- concatStreams :: MonadComp m => [Stream m a] -> Stream m a
- concatQueuedStreams :: (MonadComp m, EnqueueStrategy m s) => s -> [Stream m a] -> Stream m a
- concatPriorityStreams :: (MonadComp m, PriorityQueueStrategy m s p) => s -> [Stream m (p, a)] -> Stream m a
- splitStream :: MonadComp m => Int -> Stream m a -> Simulation m [Stream m a]
- splitStreamQueueing :: (MonadComp m, EnqueueStrategy m s) => s -> Int -> Stream m a -> Simulation m [Stream m a]
- splitStreamPrioritising :: (MonadComp m, PriorityQueueStrategy m s p) => s -> [Stream m p] -> Stream m a -> Simulation m [Stream m a]
- streamUsingId :: MonadComp m => ProcessId m -> Stream m a -> Stream m a
- prefetchStream :: MonadComp m => Stream m a -> Stream m a
- delayStream :: MonadComp m => a -> Stream m a -> Stream m a
- arrivalStream :: MonadComp m => Stream m a -> Stream m (Arrival a)
- memoStream :: MonadComp m => Stream m a -> Simulation m (Stream m a)
- zipStreamSeq :: MonadComp m => Stream m a -> Stream m b -> Stream m (a, b)
- zipStreamParallel :: MonadComp m => Stream m a -> Stream m b -> Stream m (a, b)
- zip3StreamSeq :: MonadComp m => Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
- zip3StreamParallel :: MonadComp m => Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c)
- unzipStream :: MonadComp m => Stream m (a, b) -> Simulation m (Stream m a, Stream m b)
- streamSeq :: MonadComp m => [Stream m a] -> Stream m [a]
- streamParallel :: MonadComp m => [Stream m a] -> Stream m [a]
- consumeStream :: MonadComp m => (a -> Process m ()) -> Stream m a -> Process m ()
- sinkStream :: MonadComp m => Stream m a -> Process m ()
- repeatProcess :: MonadComp m => Process m a -> Stream m a
- mapStream :: MonadComp m => (a -> b) -> Stream m a -> Stream m b
- mapStreamM :: MonadComp m => (a -> Process m b) -> Stream m a -> Stream m b
- apStream :: MonadComp m => Stream m (a -> b) -> Stream m a -> Stream m b
- apStreamM :: MonadComp m => Stream m (a -> Process m b) -> Stream m a -> Stream m b
- filterStream :: MonadComp m => (a -> Bool) -> Stream m a -> Stream m a
- filterStreamM :: MonadComp m => (a -> Process m Bool) -> Stream m a -> Stream m a
- signalStream :: MonadComp m => Signal m a -> Process m (Stream m a)
- streamSignal :: MonadComp m => Stream m a -> Process m (Signal m a)
- leftStream :: MonadComp m => Stream m (Either a b) -> Stream m a
- rightStream :: MonadComp m => Stream m (Either a b) -> Stream m b
- replaceLeftStream :: MonadComp m => Stream m (Either a b) -> Stream m c -> Stream m (Either c b)
- replaceRightStream :: MonadComp m => Stream m (Either a b) -> Stream m c -> Stream m (Either a c)
- partitionEitherStream :: MonadComp m => Stream m (Either a b) -> Simulation m (Stream m a, Stream m b)

# Stream Type

Represents an infinite stream of data in time, some kind of never-ending cons cell.

# Merging and Splitting Stream

emptyStream :: MonadComp m => Stream m a Source

An empty stream that never returns data.

mergeStreams :: MonadComp m => Stream m a -> Stream m a -> Stream m a Source

Merge two streams applying the `FCFS`

strategy for enqueuing the input data.

:: (MonadComp m, EnqueueStrategy m s) | |

=> s | the strategy applied for enqueuing the input data |

-> Stream m a | the fist input stream |

-> Stream m a | the second input stream |

-> Stream m a | the output combined stream |

Merge two streams.

If you don't know what the strategy to apply, then you probably
need the `FCFS`

strategy, or function `mergeStreams`

that
does namely this.

:: (MonadComp m, PriorityQueueStrategy m s p) | |

=> s | the strategy applied for enqueuing the input data |

-> Stream m (p, a) | the fist input stream |

-> Stream m (p, a) | the second input stream |

-> Stream m a | the output combined stream |

Merge two priority streams.

concatStreams :: MonadComp m => [Stream m a] -> Stream m a Source

Concatenate the input streams applying the `FCFS`

strategy and
producing one output stream.

:: (MonadComp m, EnqueueStrategy m s) | |

=> s | the strategy applied for enqueuing the input data |

-> [Stream m a] | the input stream |

-> Stream m a | the combined output stream |

Concatenate the input streams producing one output stream.

If you don't know what the strategy to apply, then you probably
need the `FCFS`

strategy, or function `concatStreams`

that
does namely this.

:: (MonadComp m, PriorityQueueStrategy m s p) | |

=> s | the strategy applied for enqueuing the input data |

-> [Stream m (p, a)] | the input stream |

-> Stream m a | the combined output stream |

Concatenate the input priority streams producing one output stream.

splitStream :: MonadComp m => Int -> Stream m a -> Simulation m [Stream m a] Source

Split the input stream into the specified number of output streams
after applying the `FCFS`

strategy for enqueuing the output requests.

:: (MonadComp m, EnqueueStrategy m s) | |

=> s | the strategy applied for enqueuing the output requests |

-> Int | the number of output streams |

-> Stream m a | the input stream |

-> Simulation m [Stream m a] | the splitted output streams |

Split the input stream into the specified number of output streams.

If you don't know what the strategy to apply, then you probably
need the `FCFS`

strategy, or function `splitStream`

that
does namely this.

splitStreamPrioritising Source

:: (MonadComp m, PriorityQueueStrategy m s p) | |

=> s | the strategy applied for enqueuing the output requests |

-> [Stream m p] | the streams of priorities |

-> Stream m a | the input stream |

-> Simulation m [Stream m a] | the splitted output streams |

Split the input stream into a list of output streams using the specified priorities.

# Specifying Identifier

streamUsingId :: MonadComp m => ProcessId m -> Stream m a -> Stream m a Source

Create a stream that will use the specified process identifier.
It can be useful to refer to the underlying `Process`

computation which
can be passivated, interrupted, canceled and so on. See also the
`processUsingId`

function for more details.

# Prefetching and Delaying Stream

prefetchStream :: MonadComp m => Stream m a -> Stream m a Source

Prefetch the input stream requesting for one more data item in advance while the last received item is not yet fully processed in the chain of streams, usually by the processors.

You can think of this as the prefetched stream could place its latest data item in some temporary space for later use, which is very useful for modeling a sequence of separate and independent work places.

delayStream :: MonadComp m => a -> Stream m a -> Stream m a Source

Delay the stream by one step using the specified initial value.

# Stream Arriving

arrivalStream :: MonadComp m => Stream m a -> Stream m (Arrival a) Source

Transform a stream so that the resulting stream returns a sequence of arrivals saving the information about the time points at which the original stream items were received by demand.

# Memoizing, Zipping and Uzipping Stream

memoStream :: MonadComp m => Stream m a -> Simulation m (Stream m a) Source

Memoize the stream so that it would always return the same data within the simulation run.

zipStreamSeq :: MonadComp m => Stream m a -> Stream m b -> Stream m (a, b) Source

Zip two streams trying to get data sequentially.

zipStreamParallel :: MonadComp m => Stream m a -> Stream m b -> Stream m (a, b) Source

Zip two streams trying to get data as soon as possible, launching the sub-processes in parallel.

zip3StreamSeq :: MonadComp m => Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c) Source

Zip three streams trying to get data sequentially.

zip3StreamParallel :: MonadComp m => Stream m a -> Stream m b -> Stream m c -> Stream m (a, b, c) Source

Zip three streams trying to get data as soon as possible, launching the sub-processes in parallel.

unzipStream :: MonadComp m => Stream m (a, b) -> Simulation m (Stream m a, Stream m b) Source

Unzip the stream.

streamSeq :: MonadComp m => [Stream m a] -> Stream m [a] Source

To form each new portion of data for the output stream, read data sequentially from the input streams.

This is a generalization of `zipStreamSeq`

.

streamParallel :: MonadComp m => [Stream m a] -> Stream m [a] Source

To form each new portion of data for the output stream, read data from the input streams in parallel.

This is a generalization of `zipStreamParallel`

.

# Consuming and Sinking Stream

consumeStream :: MonadComp m => (a -> Process m ()) -> Stream m a -> Process m () Source

Consume the stream. It returns a process that infinitely reads data from the stream and then redirects them to the provided function. It is useful for modeling the process of enqueueing data in the queue from the input stream.

sinkStream :: MonadComp m => Stream m a -> Process m () Source

Sink the stream. It returns a process that infinitely reads data from the stream. The resulting computation can be a moving force to simulate the whole system of the interconnected streams and processors.

# Useful Combinators

repeatProcess :: MonadComp m => Process m a -> Stream m a Source

Return a stream of values generated by the specified process.

mapStream :: MonadComp m => (a -> b) -> Stream m a -> Stream m b Source

Map the stream according the specified function.

mapStreamM :: MonadComp m => (a -> Process m b) -> Stream m a -> Stream m b Source

Compose the stream.

apStream :: MonadComp m => Stream m (a -> b) -> Stream m a -> Stream m b Source

Sequential application.

apStreamM :: MonadComp m => Stream m (a -> Process m b) -> Stream m a -> Stream m b Source

Sequential application.

filterStream :: MonadComp m => (a -> Bool) -> Stream m a -> Stream m a Source

Filter only those data values that satisfy to the specified predicate.

filterStreamM :: MonadComp m => (a -> Process m Bool) -> Stream m a -> Stream m a Source

Filter only those data values that satisfy to the specified predicate.

# Integrating with Signals

signalStream :: MonadComp m => Signal m a -> Process m (Stream m a) Source

Return a stream of values triggered by the specified signal.

Since the time at which the values of the stream are requested for may differ from
the time at which the signal is triggered, it can be useful to apply the `arrivalSignal`

function to add the information about the time points at which the signal was
actually received.

The point is that the `Stream`

is requested outside, while the `Signal`

is triggered
inside. They are different by nature. The former is passive, while the latter is active.

The resulting stream may be a root of space leak as it uses an internal queue to store the values received from the signal. The oldest value is dequeued each time we request the stream and it is returned within the computation.

Cancel the stream's process to unsubscribe from the specified signal.

streamSignal :: MonadComp m => Stream m a -> Process m (Signal m a) Source

Return a computation of the signal that triggers values from the specified stream,
each time the next value of the stream is received within the underlying `Process`

computation.

Cancel the returned process to stop reading from the specified stream.

# Utilities

replaceLeftStream :: MonadComp m => Stream m (Either a b) -> Stream m c -> Stream m (Either c b) Source

Replace the `Left`

values.

replaceRightStream :: MonadComp m => Stream m (Either a b) -> Stream m c -> Stream m (Either a c) Source

Replace the `Right`

values.

partitionEitherStream :: MonadComp m => Stream m (Either a b) -> Simulation m (Stream m a, Stream m b) Source

Partition the stream of `Either`

values into two streams.