Skip to content

Instantly share code, notes, and snippets.

@tuturto
Created February 19, 2015 20:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tuturto/0bf734ff5aca318c90ce to your computer and use it in GitHub Desktop.
Save tuturto/0bf734ff5aca318c90ce 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)
@tuturto
Copy link
Author

tuturto commented Feb 19, 2015

When the correct sequence of codes is fed into subject, "Konami!" will be printed.

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