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
TSourceThe type of items in the input sequence. Must be non-null.
TDestinationThe 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
selectorFunc<TSource, ValueTask<TDestination>>A function that asynchronously projects each input item to an output item. Useful for I/O-bound projections.
Exceptions
- ArgumentNullException
selectoris null.
SelectTransformer(Func<TSource, TDestination>)
Initializes a new instance with a synchronous selector function.
public SelectTransformer(Func<TSource, TDestination> selector)
Parameters
selectorFunc<TSource, TDestination>A function that projects each input item to an output item.
Exceptions
- ArgumentNullException
selectoris 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
itemsIAsyncEnumerable<TSource>The asynchronous source sequence.
Returns
- IAsyncEnumerable<TDestination>
An asynchronous sequence of projected items.
Exceptions
- ArgumentNullException
itemsis null.