Racket Rx
This is a small library for reactive programming in racket, growing on a on-demand basis. Some of its features are:
- A simple but essential
event-emitter%
class - Event streams inspired by Microsoft's Rx
- A event-driven
racket/gui
implementation for most common classes
This library is not to be confused with functional reactive programming. Instead, it can be seen as a building block towards it. For a full FRP language, see Racket's built-in FrTime.
(require rx/event-stream
(only-in rx/gui frame% canvas%))
(define frame (new frame% [label "Test"] [width 200] [height 300]))
(define canvas (new canvas% [parent frame]))
(define triggers
(event-stream-merge
(event-stream-filter (send canvas get-key-events)
(lambda (key-event)
(eq? (send key-event get-key-code) 'a)))
(event-stream-filter (send canvas get-mouse-events)
(lambda (mouse-event)
(eq? (send mouse-event get-event-type) 'left-down)))))
(subscribe triggers (lambda () (display (format "You did it!\n"))))
Installation
Add rx
to your deps
in info.rkt
.
#lang setup/infotab
(define deps '(("rx" "0.1.0")))
Don't forget to star if you use it so I know how much it is being used!
Documentation
The full documentation is shipped with the library itself in the form of Scribble documentation, but we also have some introductory articles for the different components of the library in plain Markdown.
License
The MIT License