Created
February 19, 2015 20:54
-
-
Save tuturto/0bf734ff5aca318c90ce to your computer and use it in GitHub Desktop.
Hy on RxPy
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
;; Adapted from https://github.com/ReactiveX/RxPY/blob/master/examples/konamicode/konamicode.py | |
(import [rx.subjects [Subject]]) | |
(setv codes [:up :up :down :down :left :right :left :right :b :a]) | |
(setv subject (Subject)) | |
(setv query (-> (.window_with_count subject 10 1) | |
(.select-many (fn [win] (.sequence-equal win codes))) | |
(.filter (fn [equal] equal)))) | |
(.subscribe query (fn [x] (print "Konami!"))) | |
(.on-next subject :up) | |
(.on-next subject :up) | |
(.on-next subject :down) | |
(.on-next subject :down) | |
(.on-next subject :left) | |
(.on-next subject :right) | |
(.on-next subject :left) | |
(.on-next subject :right) | |
(.on-next subject :b) | |
(.on-next subject :a) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When the correct sequence of codes is fed into subject, "Konami!" will be printed.