Skip to content

Instantly share code, notes, and snippets.

@kybernetikos
Last active November 26, 2015 11:08
Show Gist options
  • Select an option

  • Save kybernetikos/da89f8c655597dcfc503 to your computer and use it in GitHub Desktop.

Select an option

Save kybernetikos/da89f8c655597dcfc503 to your computer and use it in GitHub Desktop.
function itrReduce(src, reductionFn, destination) {
let result = {value: undefined, done: false}
let done = {done: true}
let latestDestinationValue = destination
return {
next: function() {
let nextIncomingOpt = src.next()
if (nextIncomingOpt.done) {
return done
} else {
latestDestinationValue = reductionFn(latestDestinationValue, nextIncomingOpt.value)
result.value = latestDestinationValue
return result
}
},
[Symbol.iterator]: function() {
return this
}
}
}
@sammyt

sammyt commented Nov 26, 2015

Copy link
Copy Markdown

I think gardening brain needs an example :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment