Here is a simple generator in C#.
IEnumerable Foo()
{
int a = 1, b = 1;
while(true)
{
yield return b;
The std.concurrency module now has a Generator class which makes this even easier (and you don't need a third-party library).
The class is an input range, so it can be used with for loops and all the standard std.range/std.algorithm functions.
import std.stdio;
import std.range;
import std.algorithm;
import std.concurrency : Generator, yield;
void main(string[] args) {
auto gen = new Generator!int({
foreach(i; 1..10)
yield(i);
});
gen
.map!(x => x*2)
.each!writeln
;
}