Struct Chunk<T>
Represents a single chunk within a streamed sequence, providing positional metadata.
public readonly record struct Chunk<T> : IEquatable<Chunk<T>>
Type Parameters
TThe type of data contained in the chunk.
- Implements
-
IEquatable<Chunk<T>>
- Inherited Members
- Extension Methods
Remarks
Chunk<T> is a lightweight, stack-allocated value type designed for high-performance streaming scenarios. It wraps individual data items with positional metadata that enables:
- First/last chunk detection for initialization and finalization logic
- Zero-based indexing for progress tracking and ordered processing
- Efficient memory usage through readonly struct semantics
This type is intended for use with IAsyncEnumerable<T> streams where handlers need to know their position within the overall sequence without buffering.
Constructors
Chunk(T, long, bool, bool)
Represents a single chunk within a streamed sequence, providing positional metadata.
public Chunk(T Data, long Index, bool IsFirst, bool IsLast)
Parameters
DataTThe data payload for this chunk.
IndexlongThe zero-based position of this chunk within the stream.
IsFirstbooltrue if this is the first chunk in the stream; otherwise, false.
IsLastbooltrue if this is the last chunk in the stream; otherwise, false.
Remarks
Chunk<T> is a lightweight, stack-allocated value type designed for high-performance streaming scenarios. It wraps individual data items with positional metadata that enables:
- First/last chunk detection for initialization and finalization logic
- Zero-based indexing for progress tracking and ordered processing
- Efficient memory usage through readonly struct semantics
This type is intended for use with IAsyncEnumerable<T> streams where handlers need to know their position within the overall sequence without buffering.
Properties
Data
The data payload for this chunk.
public T Data { get; init; }
Property Value
- T
Index
The zero-based position of this chunk within the stream.
public long Index { get; init; }
Property Value
IsFirst
public bool IsFirst { get; init; }
Property Value
IsLast
public bool IsLast { get; init; }
Property Value
IsMiddle
Gets a value indicating whether this chunk is neither the first nor the last in the stream.
public bool IsMiddle { get; }
Property Value
IsSingle
Gets a value indicating whether this is the only chunk in the stream.
public bool IsSingle { get; }