Skip to content

Instantly share code, notes, and snippets.

@yelouafi
Created July 17, 2015 02:34
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/e7d2526596bf9ac4d26e to your computer and use it in GitHub Desktop.
Save yelouafi/e7d2526596bf9ac4d26e to your computer and use it in GitHub Desktop.
// filter : (Stream a, a -> aBoolean | Promise aBoolean) => Stream a
Stream.prototype.filter = function(p) {
let tailF, futP;
return this.isEmpty || this.isAbort ? this
: this.isCons ?
( tailF = this.tail.filter(p),
futP = Promise.resolve( p(this.head) )
.then( ok => ok ? Stream.Cons(this.head, tailF) : tailF, Stream.Abort )
Stream.Future(futP))
: Stream.Future(
this.promise.then( s => s.filter(p), Stream.Abort ))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment