On Thursday, 22 October 2015 at 13:58:56 UTC, Adam D. Ruppe wrote:
D's templates are easy (you actually used one in there, the Generator is one!)

Try this:

import std.concurrency;
Generator!T sequence(T)(T i){
    return new Generator!T({
        yield(i);
        while(i > 1){
            yield(i = (i % 2) ? (i * 3 + 1) : (i >> 1));
        }
    });
}

Wonderful, thanks much! It keeps surprising me how easy it is to do stuff like this.

Reply via email to