Created
July 17, 2015 02:32
-
-
Save yelouafi/b0e8faf33b9ea7f5269b 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
// map : ( Stream a, a -> b | Promise b ) => Stream b | |
Stream.prototype.map = function(f) { | |
let tailM, futP; | |
return this.isEmpty || this.isAbort ? this | |
: this.isCons ? | |
( tailM = this.tail.map(f), | |
futP = Promise.resolve(f(this.head)) | |
.then( head => Stream.Cons(head, tailM), Stream.Abort ), | |
Stream.Future(futP)) | |
: Stream.Future( | |
this.promise.then( s => s.map(f), Stream.Abort )) | |
} | |
// result : Stream aResponseType | |
result = Stream.fromDomEvent(fetchButton, 'click').map( e => $.ajax(...) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment