Class AsyncBatchConfigurationBuilder<TBatch>
- Namespace
- AiDotNet.Extensions
- Assembly
- AiDotNet.dll
Builder for configuring async batch iteration with a fluent API.
public class AsyncBatchConfigurationBuilder<TBatch> : IAsyncEnumerable<TBatch>
Type Parameters
TBatchThe type of batch returned by iteration.
- Inheritance
-
AsyncBatchConfigurationBuilder<TBatch>
- Implements
-
IAsyncEnumerable<TBatch>
- Inherited Members
Remarks
This builder allows chaining configuration methods before async iteration. Implements IAsyncEnumerable to support await foreach loops.
Constructors
AsyncBatchConfigurationBuilder(IBatchIterable<TBatch>, int?, int)
Initializes a new instance of the AsyncBatchConfigurationBuilder.
public AsyncBatchConfigurationBuilder(IBatchIterable<TBatch> source, int? batchSize, int prefetchCount)
Parameters
sourceIBatchIterable<TBatch>The batch iterable source.
batchSizeint?Optional batch size override.
prefetchCountintNumber of batches to prefetch.
Methods
DropLast()
Drops the last incomplete batch if the dataset doesn't divide evenly.
public AsyncBatchConfigurationBuilder<TBatch> DropLast()
Returns
- AsyncBatchConfigurationBuilder<TBatch>
This builder for method chaining.
GetAsyncEnumerator(CancellationToken)
Returns an async enumerator that iterates through the batches.
public IAsyncEnumerator<TBatch> GetAsyncEnumerator(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenToken to cancel the iteration.
Returns
- IAsyncEnumerator<TBatch>
An async enumerator for the batch sequence.
KeepLast()
Keeps the last batch even if incomplete.
public AsyncBatchConfigurationBuilder<TBatch> KeepLast()
Returns
- AsyncBatchConfigurationBuilder<TBatch>
This builder for method chaining.
NoShuffle()
Disables shuffling of data before batching.
public AsyncBatchConfigurationBuilder<TBatch> NoShuffle()
Returns
- AsyncBatchConfigurationBuilder<TBatch>
This builder for method chaining.
Shuffled()
Enables shuffling of data before batching.
public AsyncBatchConfigurationBuilder<TBatch> Shuffled()
Returns
- AsyncBatchConfigurationBuilder<TBatch>
This builder for method chaining.
WithSeed(int)
Sets a random seed for reproducible shuffling.
public AsyncBatchConfigurationBuilder<TBatch> WithSeed(int seed)
Parameters
seedintThe random seed value.
Returns
- AsyncBatchConfigurationBuilder<TBatch>
This builder for method chaining.