Skip to content

Instantly share code, notes, and snippets.

@mootoh
Created March 11, 2016 08:34
Show Gist options
  • Save mootoh/6955e08e52a8e3bd3460 to your computer and use it in GitHub Desktop.
Save mootoh/6955e08e52a8e3bd3460 to your computer and use it in GitHub Desktop.
Zundoko.rxjava
// https://twitter.com/kumiromilk/status/707437861881180160
public class Zundoko {
private static final String TAG = "KIYOSHI";
private static final String ZUN = "ズン";
private static final String DOKO = "ドコ";
public static void zundoko() {
Observable o = Observable.create(new Observable.OnSubscribe<String>() {
Random rand = new Random();
@Override
public void call(Subscriber<? super String> subscriber) {
subscriber.onNext(rand.nextInt() % 2 == 0 ? "ズン" : "ドコ");
subscriber.onCompleted();
}
});
o.repeat(100000).buffer(5).subscribe(new Action1<ArrayList<String>>() {
@Override
public void call(ArrayList<String> message) {
Log.d(TAG, message.toString());
if (message.get(0) == ZUN &&
message.get(1) == ZUN &&
message.get(2) == ZUN &&
message.get(3) == ZUN &&
message.get(4) == DOKO) {
Log.d(TAG, "'キ・ヨ・シ!");
System.exit(0);
}
}
});
}
}
@mootoh
Copy link
Author

mootoh commented Mar 11, 2016

03-11 17:32:19.720 21002-21002/? D/KIYOSHI: [ドコ, ドコ, ズン, ズン, ズン]
03-11 17:32:19.721 21002-21002/? D/KIYOSHI: [ドコ, ズン, ドコ, ズン, ドコ]
03-11 17:32:19.721 21002-21002/? D/KIYOSHI: [ズン, ズン, ズン, ズン, ドコ]
03-11 17:32:19.721 21002-21002/? D/KIYOSHI: 'キ・ヨ・シ!
03-11 17:32:19.723 21002-21002/? I/art: System.exit called, status: 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment