Skip to content

Instantly share code, notes, and snippets.

@waldyrfelix
Forked from juanplopes/gist:1024221
Created June 14, 2011 03:44
Show Gist options
  • Save waldyrfelix/1024270 to your computer and use it in GitHub Desktop.
Save waldyrfelix/1024270 to your computer and use it in GitHub Desktop.
BatchAggregate
public static IEnumerable<IList<T>> BatchAggregate<T>(this IEnumerable<T> source, int batchSize)
{
var enumerator = source.GetEnumerator();
for (int page = 0; enumerator.MoveNext(); page = page + batchSize)
{
var list = source
.Skip(page)
.Take(batchSize)
.ToList();
yield return list;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment