Table of Contents

Method CollectLazy

Namespace
SodaFlow
Assembly
SodaFlow.dll

CollectLazy<T, TState, TReturn>(Stream<T>, Lazy<TState>, Func<T, TState, (TReturn ReturnValue, TState State)>)

Transform a stream with a generalized state loop (a Mealy machine) using a lazily evaluated initial state. 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> CollectLazy<T, TState, TReturn>(this Stream<T> s, Lazy<TState> initialState, Func<T, TState, (TReturn ReturnValue, TState State)> f)

Parameters

s Stream<T>

The stream.

initialState Lazy<TState>

The lazily evaluated 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.