function* foo(index) { while (index < 2) { yield index; index++; } } const iterator = foo(0); console.log(iterator.next().value); // Expected output: 0 console.log(iterator.next().value); // Expected output: 1