Class TakeWhileTransformer<T>

Namespace
Wolfgang.Etl.Transformers
Assembly
Wolfgang.Etl.Transformers.dll

A transformer that yields items from the start of the input sequence as long as a caller-supplied predicate returns true; the first item that fails the predicate stops enumeration immediately and is not yielded.

public sealed class TakeWhileTransformer<T> : ITransformAsync<T, T> where T : notnull

Type Parameters

T

The type of items flowing through the transformer. Must be non-null.

Inheritance
TakeWhileTransformer<T>
Implements
ITransformAsync<T, T>
Inherited Members
Extension Methods

Examples

// take rows until the first one that's incomplete
var head = new TakeWhileTransformer<Row>(r => r.IsComplete);

Remarks

TakeWhileTransformer<T> is the transformer equivalent of LINQ's TakeWhile<TSource>(IEnumerable<TSource>, Func<TSource, bool>): once the predicate returns false for an item, the transformer stops - the failing item is not yielded and the source is not enumerated beyond it.

Two constructors are provided: one for synchronous predicates and one for asynchronous predicates returning ValueTask<TResult>. The asynchronous form is useful for I/O-bound stop conditions such as a state-check against an external system.

Implements only Wolfgang.Etl.Abstractions.ITransformAsync<TSource, TDestination> - no progress, no cancellation, no Skip/Max - to keep the hot loop minimal.

Exceptions thrown by the predicate propagate to the caller.

Constructors

TakeWhileTransformer(Func<T, bool>)

Initializes a new instance with a synchronous predicate.

public TakeWhileTransformer(Func<T, bool> predicate)

Parameters

predicate Func<T, bool>

A function that returns true while items should continue to be yielded.

Exceptions

ArgumentNullException

predicate is null.

TakeWhileTransformer(Func<T, ValueTask<bool>>)

Initializes a new instance with an asynchronous predicate.

public TakeWhileTransformer(Func<T, ValueTask<bool>> predicate)

Parameters

predicate Func<T, ValueTask<bool>>

A function that asynchronously returns true while items should continue to be yielded. Useful for I/O-bound stop conditions.

Exceptions

ArgumentNullException

predicate is null.

Methods

TransformAsync(IAsyncEnumerable<T>)

Asynchronously yields items from the start of items while the configured predicate returns true.

public IAsyncEnumerable<T> TransformAsync(IAsyncEnumerable<T> items)

Parameters

items IAsyncEnumerable<T>

The asynchronous source sequence.

Returns

IAsyncEnumerable<T>

An asynchronous sequence containing the leading run of items for which the predicate returns true.

Exceptions

ArgumentNullException

items is null.