These are 2 different ideas about generating output in an async manner for generators.
I may be misunderstanding the problem though.
function* mappedIterator() {
var arr = [1,1,2,3];
var results = [];
arr.forEach(function (item, i) {
results[i] = 'item: ' + item;
});
// we have to use a separate structure to yield the values
for (var val of results) yield val;
}
function* stuff() {
var arr = [1,1,2,3];
// we combinded our transform and our flow control... not awesome for reusability
for (var val of arr) yield 'item: ' + val;
}
// refactored
function xform(item) {
return 'item: ' + item;
}
function* stuff() {
var arr = [1,1,2,3];
for (var val of arr) yield xform(val);
}
function stuff() {
return (for (val of [1,2,3,4]) 'item: ' + val);
}