Created
July 15, 2016 12:34
-
-
Save hannesstruss/7cf56f1ee914a1fba1312c8be57e4128 to your computer and use it in GitHub Desktop.
Easter Egg Timer
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
import java.util.List; | |
import java.util.concurrent.TimeUnit; | |
import rx.Observable; | |
import rx.subjects.PublishSubject; | |
public class KonamiTimer { | |
private final PublishSubject<Integer> input; | |
private final int triggerCount; | |
public KonamiTimer(int triggerCount) { | |
this.triggerCount = triggerCount; | |
this.input = PublishSubject.create(); | |
} | |
public void onInput() { | |
input.onNext(1); | |
} | |
/** Emits when unlocked */ | |
public Observable<Void> completed() { | |
return input | |
.buffer(5, TimeUnit.SECONDS) | |
.map(List::size) | |
.filter(x -> x >= triggerCount) | |
.map(x -> null); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment