Created
July 17, 2015 02:07
-
-
Save yelouafi/c65d1db365dea3f3928b to your computer and use it in GitHub Desktop.
This file contains 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
// reduce : ( Stream a, ((b, a) -> a), b ) -> Promise b | |
Stream.prototype.reduce = function(f, seed) { | |
return this.isEmpty ? Promise.resolve(seed) | |
: this.isAbort ? Promise.reject(this.error) | |
: this.isCons ? this.tail.reduce( f, f(seed, this.head) ) | |
: /* isFuture */ this.promise.then( s => s.reduce(f, seed), Promise.reject ) | |
} | |
Stream.seq([1,2,3,4,5], 0, 1000) | |
.reduce((x, y) => x + y, 0) | |
.then (v => console.log('sum =', v) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment