Created
March 16, 2016 17:26
-
-
Save mecab/86197def5366c7a0cd30 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
var Rx = require('rx'); | |
var Observable = Rx.Observable; | |
var match = ["ズン", "ズン", "ズン", "ズン", "ドコ"]; | |
Observable.create((obs) => { | |
obs.onNext(Math.random() > 0.5 ? "ズン" : "ドコ"); | |
obs.onCompleted(); | |
}) | |
.do((e) => { console.log(e); }) | |
.repeat() | |
.windowWithCount(5, 1) | |
.selectMany((e) => { | |
return e.zip(Observable.from(match)) | |
.scan((prev, current) => { | |
return prev && (current[0] === current[1]) | |
}, true) | |
.last() | |
}) | |
.first((e) => { return e; }) | |
.subscribe((e) => { | |
console.log("キヨシ!"); | |
}); |
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
$ node kiyoshi-rxjs.js | |
ズン | |
ズン | |
ドコ | |
ドコ | |
ズン | |
ズン | |
ドコ | |
ズン | |
ドコ | |
ズン | |
ドコ | |
ドコ | |
ズン | |
ズン | |
ドコ | |
ズン | |
ズン | |
ズン | |
ズン | |
ドコ | |
キヨシ! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment