Class SelectTransformer<TSource, TDestination>

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

A transformer that projects each item from the input sequence through a caller-supplied selector function, returning the result.

public sealed class SelectTransformer<TSource, TDestination> : ITransformAsync<TSource, TDestination> where TSource : notnull where TDestination : notnull

Type Parameters

TSource

The type of items in the input sequence. Must be non-null.

TDestination

The type of items produced by the selector. Must be non-null.

Inheritance
SelectTransformer<TSource, TDestination>
Implements
ITransformAsync<TSource, TDestination>
Inherited Members
Extension Methods

Examples

// synchronous projection
var toUpper = new SelectTransformer<string, string>(s => s.ToUpperInvariant());

// asynchronous projection (I/O-bound)
var lookup = new SelectTransformer<int, Customer>
(
    async id => await customerService.GetByIdAsync(id).ConfigureAwait(false)
);

Remarks

SelectTransformer<TSource, TDestination> is the transformer equivalent of LINQ's Select<TSource, TResult>(IEnumerable<TSource>, Func<TSource, TResult>): it applies a function to each input item and yields the result.

Two constructors are provided: one for synchronous selectors and one for asynchronous selectors returning ValueTask<TResult>. The asynchronous form is useful for I/O-bound projections (database lookups, HTTP calls, etc.).

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. See the benchmarks project for measurements motivating this choice.

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

Constructors

SelectTransformer(Func<TSource, ValueTask<TDestination>>)

Initializes a new instance with an asynchronous selector function.

public SelectTransformer(Func<TSource, ValueTask<TDestination>> selector)

Parameters

selector Func<TSource, ValueTask<TDestination>>

A function that asynchronously projects each input item to an output item. Useful for I/O-bound projections.

Exceptions

ArgumentNullException

selector is null.

SelectTransformer(Func<TSource, TDestination>)

Initializes a new instance with a synchronous selector function.

public SelectTransformer(Func<TSource, TDestination> selector)

Parameters

selector Func<TSource, TDestination>

A function that projects each input item to an output item.

Exceptions

ArgumentNullException

selector is null.

Methods

TransformAsync(IAsyncEnumerable<TSource>)

Asynchronously projects each item from items through the configured selector and yields the result.

public IAsyncEnumerable<TDestination> TransformAsync(IAsyncEnumerable<TSource> items)

Parameters

items IAsyncEnumerable<TSource>

The asynchronous source sequence.

Returns

IAsyncEnumerable<TDestination>

An asynchronous sequence of projected items.

Exceptions

ArgumentNullException

items is null.