Despite my attempt to use es6 generators to set the value/done as I want, I am struggling to achieve the desired outcome. Whenever I try to set a value, it ends up in the "value" field, while the generator always returns "done: false" when I am actually aiming for "done: true".
var A = [
{id: 1, page: 'page one'},
{id: 2, page: 'page two'},
{id: 3, page: 'page three'},
{id: 4, page: 'page four'},
]
function* gen(iteree) {
let input = yield null
while(true)
input = yield iteree(input) ? iteree(input) : { done: true}
}
// more enhancements to come, just showcasing a
// function passing example here
let inter = (a) => {
return A[a]
}
let c = gen(inter)
console.log(c.next())
console.log(c.next(4)) // <-- **I want this to yield {value: null, done: true}**
however, it outputs: {value: {done: true}, done: false}