I am trying to split a collection into multiple collections while maintaining a sort I have on the collection. I have tried using the following extension method, but it breaks
A slightly more clean LINQ approach, for this rather old question:
public static IEnumerable> Partition(this IEnumerable source, int n)
{
var count = source.Count();
return source.Select((x, i) => new { value = x, index = i })
.GroupBy(x => x.index / (int)Math.Ceiling(count / (double)n))
.Select(x => x.Select(z => z.value));
}