Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Created July 17, 2015 02:32
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 yelouafi/b0e8faf33b9ea7f5269b to your computer and use it in GitHub Desktop.
Save yelouafi/b0e8faf33b9ea7f5269b to your computer and use it in GitHub Desktop.
// 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