Question: It seems a common pattern to consume a queue with a pool of processes, i.e.

```
Pool(2).map(f, xs)

```

but where the body of f may append to the items being mapped over, e.g.

```
from multiprocessing import Pool

xs = [0]

def f(n):
    global xs
    if n < 10:
        xs.append(n + 1)
    return n

Pool(2).map(f, xs)

```

Expecting to return `[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]`

I realize it's possible to build this "[manually](https://gist.github.com/anfedorov/7dae4d7dc7a959ae438b2fa33b343f6c)" with the primitives provided by mt, but it seems like a common enough pattern that there must be a common solution. Do you know of one?

Answer: 
How about this - 

```
var numOfChunks = lines.Count / chunkSize; // initial number of chunks
if(lines.Count % chunkSize > 0) { numOfChunks++; } // add one chunk for remainder if there is a remainder
for (var i = 0; i <= numOfChunks; i++)
{
     var chunk = lines.Skip(i * chunkSize).Take(chunkSize);
    // Do something with chunk, like writing to file
}

```
Linq's `Take` and `Skip` may help here.

```
public static List<List<T>> ChunkBy<T>(this List<T> source, int chunkSize) 
{
    var pages = new List<List<T>>();
    var page = 0;
    while(source.Any()) {
        var l = source.Skip(page++*chunkSize).Take(chunkSize).ToList();
        if(!l.Any()) break;
        pages.Add(l);
    }
    return pages;
}

```