Class SkipWhileTransformer<T>
- Namespace
- Wolfgang.Etl.Transformers
- Assembly
- Wolfgang.Etl.Transformers.dll
A transformer that skips items from the start of the input sequence as long as a caller-supplied predicate returns true; once the predicate returns false for an item, that item and every item after it are yielded without further predicate evaluation.
public sealed class SkipWhileTransformer<T> : ITransformAsync<T, T> where T : notnull
Type Parameters
TThe type of items flowing through the transformer. Must be non-null.
- Inheritance
-
SkipWhileTransformer<T>
- Implements
-
ITransformAsync<T, T>
- Inherited Members
- Extension Methods
Examples
// skip leading blank rows; once a non-blank row appears, yield everything from there
var fromFirstReal = new SkipWhileTransformer<Row>(r => r.IsBlank);
Remarks
SkipWhileTransformer<T> is the transformer equivalent of LINQ's SkipWhile<TSource>(IEnumerable<TSource>, Func<TSource, bool>). The predicate is called on each item only until it first returns false; after that, every remaining item flows through unchanged.
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 start 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
SkipWhileTransformer(Func<T, bool>)
Initializes a new instance with a synchronous predicate.
public SkipWhileTransformer(Func<T, bool> predicate)
Parameters
Exceptions
- ArgumentNullException
predicateis null.
SkipWhileTransformer(Func<T, ValueTask<bool>>)
Initializes a new instance with an asynchronous predicate.
public SkipWhileTransformer(Func<T, ValueTask<bool>> predicate)
Parameters
predicateFunc<T, ValueTask<bool>>A function that asynchronously returns true while items should be skipped. Useful for I/O-bound start conditions.
Exceptions
- ArgumentNullException
predicateis null.
Methods
TransformAsync(IAsyncEnumerable<T>)
Asynchronously skips items from the start of items while the
configured predicate returns true, then yields the rest unchanged.
public IAsyncEnumerable<T> TransformAsync(IAsyncEnumerable<T> items)
Parameters
itemsIAsyncEnumerable<T>The asynchronous source sequence.
Returns
- IAsyncEnumerable<T>
An asynchronous sequence containing every item from the first one where the predicate returns false to the end of
items.
Exceptions
- ArgumentNullException
itemsis null.