ExperimentalEnumerableBatchTSource, TResult(IEnumerableTSource, Int32, ArrayPoolTSource, FuncICurrentBufferTSource, TResult) Method

Batches the source sequence into sized buckets using an array pool to rent arrays to back each bucket and returns a sequence of elements projected from each bucket.

Definition

Namespace: MoreLinq.Experimental
Assembly: MoreLinq (in MoreLinq.dll) Version: 4.1.0+0e154ef592f33ce0f6f3d534a9eedee273f0ce72
C#
public static IEnumerable<TResult> Batch<TSource, TResult>(
	this IEnumerable<TSource> source,
	int size,
	ArrayPool<TSource> pool,
	Func<ICurrentBuffer<TSource>, TResult> resultSelector
)

Parameters

source  IEnumerableTSource
The source sequence.
size  Int32
Size of buckets.
pool  ArrayPoolTSource
The pool used to rent the array for each bucket.
resultSelector  FuncICurrentBufferTSource, TResult
A function that projects a result from the current bucket.

Type Parameters

TSource
Type of elements in source sequence.
TResult
Type of elements of the resulting sequence.

Return Value

IEnumerableTResult
A sequence whose elements are projected from each bucket (returned by resultSelector).

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableTSource. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

This operator uses deferred execution and streams its results (however, each bucket provided to resultSelector is buffered).

Each bucket is backed by a rented array that may be at least size in length.

When more than one bucket is produced, all buckets except the last is guaranteed to have size elements. The last bucket may be smaller depending on the remaining elements in the source sequence.

Each bucket is pre-allocated to size elements. If size is set to a very large value, e.g. MaxValue to effectively disable batching by just hoping for a single bucket, then it can lead to memory exhaustion (OutOfMemoryException).

See Also