// Copyright Epic Games, Inc. All Rights Reserved. using System; using System.Collections.Generic; using System.Text; namespace EpicGames.Core { /// /// Extension methods for /// public static class EnumerableExtensions { /// /// Split the sequence into batches of at most the given size /// /// The element type /// Sequence to split into batches /// Maximum size of each batch /// Sequence of batches public static IEnumerable> Batch(this IEnumerable Sequence, int BatchSize) { List Elements = new List(BatchSize); foreach (TElement Element in Sequence) { Elements.Add(Element); if (Elements.Count == BatchSize) { yield return Elements; Elements.Clear(); } } if (Elements.Count > 0) { yield return Elements; } } } }