Class Flow<T>
- Namespace
- PatternKit.Behavioral.Iterator
- Assembly
- PatternKit.Core.dll
A fluent, functional pipeline ("flow") over an IEnumerable<T> supporting transformation (Map<TOut>(Func<T, TOut>)), filtering (Filter(Func<T, bool>)), flattening (FlatMap<TOut>(Func<T, IEnumerable<TOut>>)), side-effects (Tee(Action<T>)), sharing + forking (Share(), Fork()), and logical branching (Branch(Func<T, bool>)).
public sealed class Flow<T> : IEnumerable<T>, IEnumerable
Type Parameters
T
- Inheritance
-
Flow<T>
- Implements
-
IEnumerable<T>
- Inherited Members
- Extension Methods
Remarks
Flow<T> composes *lazy* LINQ-style transformations without immediately enumerating the underlying source. Calling Share() turns the pipeline into a SharedFlow<T>, which materializes elements through a ReplayableSequence<T> only once and enables safe multi-consumer forking + partitioning without re-enumerating upstream.
The goal is to demonstrate a custom iterator abstraction similar in spirit to an Rx pipe, but
with synchronous, pull-based semantics and explicit replay / branching control.
Thread-safety: Flows and shared flows are not thread-safe; confine to a single logical thread.
Methods
Filter(Func<T, bool>)
Filter elements via predicate.
public Flow<T> Filter(Func<T, bool> predicate)
Parameters
Returns
- Flow<T>
FlatMap<TOut>(Func<T, IEnumerable<TOut>>)
Flat-map each element to a (possibly empty) inner sequence.
public Flow<TOut> FlatMap<TOut>(Func<T, IEnumerable<TOut>> selector)
Parameters
selectorFunc<T, IEnumerable<TOut>>
Returns
- Flow<TOut>
Type Parameters
TOut
From(IEnumerable<T>)
Create a flow from an existing source (no defensive copy; deferred).
public static Flow<T> From(IEnumerable<T> source)
Parameters
sourceIEnumerable<T>
Returns
- Flow<T>
GetEnumerator()
Returns an enumerator that iterates through the collection.
public IEnumerator<T> GetEnumerator()
Returns
- IEnumerator<T>
An enumerator that can be used to iterate through the collection.
Map<TOut>(Func<T, TOut>)
Map each element via selector.
public Flow<TOut> Map<TOut>(Func<T, TOut> selector)
Parameters
selectorFunc<T, TOut>
Returns
- Flow<TOut>
Type Parameters
TOut
Share()
Turn this flow into a shared replayable stream for safe forking / branching.
public SharedFlow<T> Share()
Returns
- SharedFlow<T>
Tee(Action<T>)
Run a side-effect for each element while preserving the element.
public Flow<T> Tee(Action<T> effect)
Parameters
effectAction<T>
Returns
- Flow<T>