Created
July 17, 2015 02:34
-
-
Save yelouafi/e7d2526596bf9ac4d26e 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
// 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