Created
August 9, 2017 14:33
-
-
Save sandcastle/153d039c9580992f943c68bb0ef8d999 to your computer and use it in GitHub Desktop.
Partition a list into many partitions of equal size. Handy for things like migrations where you want to break things into "buckets"
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
| internal static class LinqExtensions | |
| { | |
| public static List<List<T>> Partition<T>(this IEnumerable<T> list, int partitionSize) | |
| { | |
| var i = 0; | |
| var splits = from item in list | |
| group item by i++ / partitionSize into part | |
| select part.ToList(); | |
| return splits.ToList(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment