Class ChunkExtensions
Extension methods that attach positional metadata to a stream, producing Chunk<T> values.
public static class ChunkExtensions
- Inheritance
-
ChunkExtensions
- Inherited Members
Methods
AsSingleChunk<T>(T)
Presents a single value as a one-element chunked stream.
public static IAsyncEnumerable<Chunk<T>> AsSingleChunk<T>(this T data)
Parameters
dataTThe value to wrap.
Returns
- IAsyncEnumerable<Chunk<T>>
A stream of exactly one chunk, which is both the first and the last (IsSingle is true).
Type Parameters
TThe value type.
Remarks
Use this where an API requires a chunked stream but the result is known to be a single value, so the caller does not have to hand-construct the positional metadata.
WithChunkInfo<T>(IAsyncEnumerable<T>)
Wraps each element of a stream in a Chunk<T> carrying its position.
public static IAsyncEnumerable<Chunk<T>> WithChunkInfo<T>(this IAsyncEnumerable<T> source)
Parameters
sourceIAsyncEnumerable<T>The stream to annotate.
Returns
- IAsyncEnumerable<Chunk<T>>
A stream of chunks, each describing its own position within the sequence.
Type Parameters
TThe element type.
Exceptions
- ArgumentNullException
sourceis null.
WithChunkInfo<T>(IAsyncEnumerable<T>, CancellationToken)
Wraps each element of a stream in a Chunk<T> carrying its position.
public static IAsyncEnumerable<Chunk<T>> WithChunkInfo<T>(this IAsyncEnumerable<T> source, CancellationToken cancellationToken)
Parameters
sourceIAsyncEnumerable<T>The stream to annotate.
cancellationTokenCancellationTokenA token that cancels enumeration.
Returns
- IAsyncEnumerable<Chunk<T>>
A stream of chunks, each describing its own position within the sequence.
Type Parameters
TThe element type.
Remarks
The source is read one element ahead so that each chunk can report whether it is the last. An empty source yields no chunks; a single-element source yields one chunk that is both first and last (IsSingle).
Exceptions
- ArgumentNullException
sourceis null.