Last active
August 29, 2015 14:25
-
-
Save yelouafi/4a787fb35ce1f0981866 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
// aBoolean : Object (JavaScript view of truth) | |
// filter : (Stream a, a -> aBoolean) => Stream a | |
Stream.prototype.filter = function(pred) { | |
return this.isEmpty || this.isAbort ? this | |
: this.isCons ? | |
(pred(this.head) ? | |
Stream.Cons(this.head, this.tail.filter(pred)) | |
: this.tail.filter(pred)) | |
: Stream.Future( | |
this.promise.then( | |
s => s.filter(pred), | |
Stream.Abort)) | |
} | |
//filters a stream of keypress events to yield only Ctrl keys | |
Stream.fromDomEvent(document, 'keydown').filter( e => e.keyCode === 17 ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment