Batching with LINQ


static IEnumerable<IEnumerable<T>> Batch<T>(this IEnumerable<T> source, int batchSize)
{
    return source.Select((item, inx) => new { item, inx })
    			 .GroupBy(x => x.inx / batchSize)
				 .Select(g => g.Select(x => x.item));
}

https://stackoverflow.com/questions/13731796/create-batches-in-linq


Revision #4
Created 2022-09-22 20:44:50 UTC by Guest
Updated 2023-03-31 22:03:59 UTC by Guest