Created
January 8, 2011 19:31
-
-
Save atheken/771082 to your computer and use it in GitHub Desktop.
ChunkIt
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
public class ChunkUtils | |
{ | |
public static IEnumerable<T> Chunk(Func<int,IEnumerable<T>> chunkFunc){ | |
var taken = 0; | |
var last = 0; | |
do{ | |
last = taken; | |
var values = chunkFunc(taken);//taken is the "skip" count, the "take" count will have been closed into the chunkFunc. | |
foreach(var v in values) | |
{ | |
taken++; | |
yield return v; | |
} | |
}while(taken == last); | |
yield break; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment