function* indexGenerator(){
var index = 0;
while(true) {
yield index++;
}
}
const g = indexGenerator();
console.log(g.next().value); // => 0
console.log(g.next().value); // => 1
function xrange($min, $max) {
for ($i = $min; $i <= $max; $i++) {
yield $i;
}
}
//[…]
foreach (xrange(1, 10) as $key => $value) {
echo "$key => $value" . PHP_EOL;
}
function* generator() {
yield 1;
yield 2;
yield 3;
}
const gen = generator(); // "Generator { }"
console.log(gen.next().value); // 1
console.log(gen.next().value); // 2
console.log(gen.next().value); // 3