Table of Contents

Method Sample

Namespace
SodaFlow
Assembly
SodaFlow.dll

Sample<T>(Behavior<T>)

Sample the current value of the behavior.

public static T Sample<T>(this Behavior<T> b)

Parameters

b Behavior<T>

The behavior.

Returns

T

The current value of the behavior.

Type Parameters

T

The type of the behavior.

Remarks

The functions that the primitives give to a stream can call this method. Those primitives are Map<T, TResult>(Stream<T>, Func<T, TResult>) , where a call here is the same as a snapshot of the behavior, Snapshot<T, T1, TResult>(Stream<T>, Behavior<T1>, Func<T, T1, TResult>) , Filter<T>(Stream<T>, Func<T, bool>) , and Merge<T>(Stream<T>, Stream<T>, Func<T, T, T>) .

It can be best to use this method in an explicit transaction (using Run<T>(Func<T>) or RunVoid(Action)). For example, a b.Sample() in an explicit transaction, with a b.Updates().ListenStrong(...), captures the current value and each update. The code keeps each value between the two.