Skip to content

Instantly share code, notes, and snippets.

@mecab
Created March 16, 2016 17:26
Show Gist options
  • Save mecab/86197def5366c7a0cd30 to your computer and use it in GitHub Desktop.
Save mecab/86197def5366c7a0cd30 to your computer and use it in GitHub Desktop.
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("キヨシ!");
});
$ node kiyoshi-rxjs.js
ズン
ズン
ドコ
ドコ
ズン
ズン
ドコ
ズン
ドコ
ズン
ドコ
ドコ
ズン
ズン
ドコ
ズン
ズン
ズン
ズン
ドコ
キヨシ!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment