Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Created July 17, 2015 02:13
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/20d56e7fab5baa9ea2af to your computer and use it in GitHub Desktop.
Save yelouafi/20d56e7fab5baa9ea2af to your computer and use it in GitHub Desktop.
// takeUntil : (Stream a, Promise) => Stream a
Stream.prototype.takeUntil = function(untilP) {
return this.isEmpty || this.isAbort ? this
: this.isCons ? Stream.Cons( this.head, this.tail.takeUntil(untilP) )
: Stream.Future(
// can you spot a problem here ?
Promise.race([
untilP.then( _ => Stream.Empty, Stream.Abort ),
this.promise.then( s => s.takeUntil(untilP), Stream.Abort )
]))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment