Class TakeTransformer<T>

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

A transformer that yields at most a fixed number of items from the start of the input sequence.

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

Type Parameters

T

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

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

Examples

// sample the first 100 rows for a dev / debug loop
var head = new TakeTransformer<Row>(count: 100);

Remarks

TakeTransformer<T> is the transformer equivalent of LINQ's Take<TSource>(IEnumerable<TSource>, int): it yields the first Count items from the source and stops, never enumerating beyond what was requested.

A count of 0 or negative is not an error - the transformer yields no items and does not enumerate the source at all (matches the BCL contract for Enumerable.Take).

Useful for windowing the head of a stream when the upstream extractor does not expose a row-count limit, and as a building block in composed pipelines.

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

Constructors

TakeTransformer(int)

Initializes a new instance that yields at most count items.

public TakeTransformer(int count)

Parameters

count int

The maximum number of items to yield. A value of 0 or less results in an empty output sequence and the source is not enumerated.

Properties

Count

The maximum number of items this transformer will yield.

public int Count { get; }

Property Value

int

Methods

TransformAsync(IAsyncEnumerable<T>)

Asynchronously yields at most Count items from the start of items.

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

Parameters

items IAsyncEnumerable<T>

The asynchronous source sequence.

Returns

IAsyncEnumerable<T>

An asynchronous sequence containing the first Count items from items, or all items if the source is shorter than Count. Empty if Count is 0 or negative.

Exceptions

ArgumentNullException

items is null.