Class WhereTransformer<T>

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

A transformer that yields each item from the input sequence for which a caller-supplied predicate returns true.

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

Type Parameters

T

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

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

Examples

// synchronous filter
var activeOnly = new WhereTransformer<Customer>(c => c.IsActive);

// asynchronous filter (I/O-bound)
var existsInDb = new WhereTransformer<int>
(
    async id => await db.CustomerExistsAsync(id).ConfigureAwait(false)
);

Remarks

WhereTransformer<T> is the transformer equivalent of LINQ's Where<TSource>(IEnumerable<TSource>, Func<TSource, bool>): it tests each input item against a predicate and yields only those that pass.

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 filter conditions such as a database existence check.

This type deliberately implements only Wolfgang.Etl.Abstractions.ITransformAsync<TSource, TDestination> and does not inherit from Wolfgang.Etl.Abstractions.TransformerBase<TSource, TDestination, TProgress>. It carries no progress reporting, no cancellation token, and no item counters - keeping the hot loop as small as possible for use as a building block in composed pipelines. Callers needing cancellation or windowing should compose with dedicated transformers (for example a future SkipTransformer / TakeTransformer / BufferedTransformer).

Exceptions thrown by the predicate propagate to the caller. Callers that need to handle errors per item should do so inside the predicate itself.

Constructors

WhereTransformer(Func<T, bool>)

Initializes a new instance with a synchronous predicate.

public WhereTransformer(Func<T, bool> predicate)

Parameters

predicate Func<T, bool>

A function that returns true for items to be yielded.

Exceptions

ArgumentNullException

predicate is null.

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

Initializes a new instance with an asynchronous predicate.

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

Parameters

predicate Func<T, ValueTask<bool>>

A function that asynchronously returns true for items to be yielded. Useful for I/O-bound filter conditions.

Exceptions

ArgumentNullException

predicate is null.

Methods

TransformAsync(IAsyncEnumerable<T>)

Asynchronously yields each item from items for which 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 only the items that satisfy the predicate.

Exceptions

ArgumentNullException

items is null.