public static IEnumerable<TResult> Batch<TSource, TResult>(
this IEnumerable<TSource> source,
int size,
Func<IEnumerable<TSource>, TResult> resultSelector
)
<ExtensionAttribute>
Public Shared Function Batch(Of TSource, TResult) (
source As IEnumerable(Of TSource),
size As Integer,
resultSelector As Func(Of IEnumerable(Of TSource), TResult)
) As IEnumerable(Of TResult)
public:
[ExtensionAttribute]
generic<typename TSource, typename TResult>
static IEnumerable<TResult>^ Batch(
IEnumerable<TSource>^ source,
int size,
Func<IEnumerable<TSource>^, TResult>^ resultSelector
)
[<ExtensionAttribute>]
static member Batch :
source : IEnumerable<'TSource> *
size : int *
resultSelector : Func<IEnumerable<'TSource>, 'TResult> -> IEnumerable<'TResult>
This operator uses deferred execution and streams its results (buckets are streamed but their content buffered).
When more than one bucket is streamed, 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).