I was inspired by my good friend Nick's latest blog entry Return of the Batch Enumerable.
Here he demonstrates a neat idea of using extension methods and yield to split an IEnumerable into arbitrary batches.
My version is slightly less efficient, but treats the batches as separate lazy collections - so you can use it on multiple threads etc.
I've also added a Split extension, which I'll describe - but first, the code!
The InBatches returns the same output as Nicks:
And the Split batches the output across the collections:
So this gives you 2 different batch splitting methods for a generic enumerable.
I love this stuff.