The generator.next() method
It already is dealt with via destructuring assignments:
function* gen() {
var {x, y, z} = yield [1, 2, 3]
return x && y || z
}
var g = gen()
var [a, b, c] = g.next().value
assert(a === 1)
assert(b === 2)
assert(c === 3)
var res = g.send({x: true, y: false, z: true}).value
assert(res === true)
No .value anywhere, though.
g.next()
returns {value: [1, 2, 3], done: false}
for me, so .value
is needed here. Or do you mean something else?
I just wanted to demonstrate the point, I couldn't remember what the exact API agreed upon for gen.send
is.
I believe .value is indeed correct, although as André alludes to, .send() has been replaced by .next().
Working example in Traceur (this is fun!)
André Bargull wrote:
g.next()
returns{value: [1, 2, 3], done: false}
for me, so .value is needed here. Or do you mean something else?
Sorry (to Forbes), I was thinking of when for-of orchestrates.
Domenic Denicola wrote:
[Working example in Traceur][1] (this is fun!)
Yes, +lots for Traceur.
I'd rather be corrected when I'm right than ignored when I'm wrong, and at the moment I'm still pretty new to the specifics of ES6 APIs :)
I wondered why it would be possible to send only one variable via this method?
Knowing that we will have the opportunity to use destructuring assignments, why can't we deal on this "problem"?