Method Collect
- Namespace
- SodaFlow
- Assembly
- SodaFlow.dll
Collect<T, TState, TReturn>(Stream<T>, TState, Func<T, TState, (TReturn ReturnValue, TState State)>)
Transform a stream with a generalized state loop (a Mealy machine). This calls the function with the input and the previous state, and the function returns the new state and the output value.
public static Stream<TReturn> Collect<T, TState, TReturn>(this Stream<T> s, TState initialState, Func<T, TState, (TReturn ReturnValue, TState State)> f)
Parameters
sStream<T>The stream.
initialStateTStateThe initial state of the Mealy machine.
fFunc<T, TState, (TReturn ReturnValue, TState State)>Function to apply to update the state. It can make FRP logic or use Sample<T>(Cell<T>), and this is then equivalent to snapshotting the cell with Snapshot<T, TResult>(Stream<T>, Cell<TResult>). Apart from this, the function must be pure.
Returns
- Stream<TReturn>
A stream resulting from the transformation of this stream by the Mealy machine.
Type Parameters
TThe type of the stream.
TStateThe type of the state of the Mealy machine.
TReturnThe type of the return value.