GeneratorAn iterable made from a yielding block: each ^> in the block becomes an element.
each: runs the block in a fiber and forwards every ^> to the consumer. Consumed lazily through an Iterator (e.g. .take:), so even infinite generators are usable.
var naturals = Generator.from:{ var i = 0; { true }.whileDo:{ ^>i; i = i + 1 } }; (naturals.lazyCollect:{ |x| x * x }).take:4 "* -> #(0 1 4 9)
A Generator over the block's ^> yields.
(Generator.from:{ ^>1; ^>2 }).list "* -> #(1 2)
Call the consumer once per ^> yield, running the generator block in a fresh fiber - so every each: restarts the generator from the top.