Here is a simple generator in C#.
IEnumerable<int> Foo()
{
int a = 1, b = 1;
while(true)
{
yield return b;
int temp = a + b;
a = b;
b = temp;
}
}
How do I write a similar generator in Digital Mars D?
(The question is about the yield return statement)
Thanks!
Update. That's interesting. Since I'm just generating a mathematical sequence, using recurrence may be a good option.
auto fib = recurrence!("a[n-1] + a[n-2]")(1, 1);
foreach (e; take(fib, 10)) // <- prints first ten numbers from the sequence
{
writeln(e);
}