Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Last active August 29, 2015 14:25
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/de0cfcd1b6aa54f45259 to your computer and use it in GitHub Desktop.
Save yelouafi/de0cfcd1b6aa54f45259 to your computer and use it in GitHub Desktop.
// zip : (Stream a, Stream b) => Stream [a,b]
Stream.prototype.zip = function(s2) {
return this.isEmpty || this.isAbort ? this
: s2.isEmpty || s2.isAbort ? s2
: this.isCons && s2.isCons ?
Stream.Cons([this.head, s2.head], this.tail.zip(s2.tail))
: this.isCons && s2.isFuture ?
Stream.Future(s2.promise.then(s => this.zip(s), Stream.Abort))
: // this.isFuture && (s2.isCons || s2.isFuture)
Stream.Future(this.promise.then(s => s.zip(s2), Stream.Abort))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment