Skip to content

Instantly share code, notes, and snippets.

@gyaresu
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyaresu/2960e6e8add528940bfb to your computer and use it in GitHub Desktop.
Save gyaresu/2960e6e8add528940bfb to your computer and use it in GitHub Desktop.
Why won't yield return from within a `.map` callback? - stackoverflow
// https://stackoverflow.com/questions/30498103/why-wont-yield-return-from-within-a-map-callback/30498924#30498924
// WARNING: UNTESTED!
function *mapGen (arr,callback) {
for (var i=0; i<arr.length; i++) {
yield callback(arr[i])
}
}
Array.prototype.mapGen = mapGen;
function *upper (items) {
yield* items.mapGen(function (item) {
try {
yield item.toUpperCase()
} catch (e) {
yield 'null'
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment