JavaScript generators allow you to yield actions in a procedural manner.
Is it possible to skip/invoke specific yields natively?
Given the below example, how could this be achieved?
I would like to yield values 1, 3 & 5.
function *getVal() {
yield 1;
yield 2;
yield 3;
yield 4;
yield 5;
}
let x = getVal();
// I want to yield ONLY values 1 , 3 , & 5
// Here val will equal 1
let val = x.next();
// I now want to val to equal 3
val = << skip second yield and hit 3 >>
// Is it possible to skip a yield natively?
// ...
x.next()before assigningx.next()toval?yieldpauses the function until it starts again, but you can't skip part of a generator from outside any more than you can reach in and skip part of any other function.