-
-
Save wuxianliang/4521f65bb3dc53d319fe 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