Created
October 2, 2022 18:03
-
-
Save AThraen/ee06d7ef18f149c7109881d54a1124e7 to your computer and use it in GitHub Desktop.
Chunkify, breaks up a generic enumerator into batches (chunks) of a given size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected IEnumerable<List<G>> Chunkify<G>(IEnumerable<G> Source,int ChunkSize) | |
| { | |
| List<G> chunk=new List<G>(ChunkSize); | |
| foreach(var e in Source) | |
| { | |
| chunk.Add(e); | |
| if(chunk.Count > ChunkSize) | |
| { | |
| yield return chunk; | |
| chunk.Clear(); | |
| } | |
| } | |
| if (chunk.Any()) yield return chunk; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment