Table of Contents

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

s Stream<T>

The stream.

initialState TState

The initial state of the Mealy machine.

f Func<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

T

The type of the stream.

TState

The type of the state of the Mealy machine.

TReturn

The type of the return value.