Skip to content

Instantly share code, notes, and snippets.

@fuqunaga
Last active December 26, 2018 09:29
Show Gist options
  • Save fuqunaga/0e96c2cfdf092bbfd0fba195699a1945 to your computer and use it in GitHub Desktop.
Save fuqunaga/0e96c2cfdf092bbfd0fba195699a1945 to your computer and use it in GitHub Desktop.
IEnumerableChunks
public static class IEnumerableExtensions
{
public static IEnumerable<IEnumerable<T>> Chunks<T>(this IEnumerable<T> list, int size)
{
var buf = list;
while (buf.Any())
{
yield return buf.Take(size);
buf = buf.Skip(size);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment