Skip to content

Instantly share code, notes, and snippets.

@wuxianliang
Forked from tuturto/gist:0bf734ff5aca318c90ce
Created January 9, 2016 16:32
Show Gist options
  • Save wuxianliang/4521f65bb3dc53d319fe to your computer and use it in GitHub Desktop.
Save wuxianliang/4521f65bb3dc53d319fe to your computer and use it in GitHub Desktop.
Hy on RxPy
;; 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