Last active
November 26, 2015 11:08
-
-
Save kybernetikos/da89f8c655597dcfc503 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think gardening brain needs an example :)