mirror of
https://github.com/simtactics/mysimulation.git
synced 2025-03-15 14:51:21 +00:00
16 lines
443 B
C#
16 lines
443 B
C#
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace FSO.Common.Utils
|
|||
|
{
|
|||
|
public static class LinqUtils
|
|||
|
{
|
|||
|
public static IEnumerable<IEnumerable<T>> Batch<T>(this IEnumerable<T> items, int maxItems)
|
|||
|
{
|
|||
|
return items.Select((item, index) => new { item, index })
|
|||
|
.GroupBy(x => x.index / maxItems)
|
|||
|
.Select(g => g.Select(x => x.item));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|