english
english copied to clipboard
gem: Using Fibers with ranges
From @wilzbach on May 18, 2016 13:12
This is one of my favorite features in D, but it took me a while to discover this. This allows one to write pretty sophisticated lazy algorithms by just saving keeping a reference to the stack. Ali had a great talk about this year -> http://dconf.org/2016/talks/cehreli.html
import std.concurrency: Generator,yield;
auto r = new Generator!int(
{
foreach (i; 1 .. 10)
yield(i);
});
import std.range: iota;
import std.algorithm.comparison: equal;
assert(r.equal(iota(1, 10)));
https://dlang.org/library/std/concurrency/generator.html
Copied from original issue: stonemaster/dlang-tour#133
From @stonemaster on May 18, 2016 14:5
That's a good one. There is already fiber's section maybe it fits there.