I'd like to evaluate values lazily and then process them one by one, using e.g. `map`. One of the steps requires processing the values in chunks. I was thinking of using a Generator for lazy evaluation, but I can't seem to make it work with the `chunks`.

How can I make `std.range.chunks` work with a generator?


import std.stdio;
import std.concurrency: Generator, yield;
import std.range:chunks;
import std.algorithm:map;


void main()
{

    auto gen = new Generator!int(
    {
        foreach (i; 1 .. 10)
            yield(i);
    });


    foreach (n; chunks(gen, 2))
    {
        writeln(n);
    }
}

Build fails with the following error:

source/app.d(18,23): Error: template std.range.chunks cannot deduce function from argument types !()(Generator!int, int), candidates are: /usr/include/dmd/phobos/std/range/package.d(6940,15): std.range.chunks(Source)(Source source, size_t chunkSize) if (isForwardRange!Source)
dmd failed with exit code 1.

Reply via email to