Last active
February 12, 2021 14:30
-
-
Save oakes/f2c19782f9b540de4eee09712472d825 to your computer and use it in GitHub Desktop.
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
{:deps {net.sekao/odoyle-rules {:mvn/version "RELEASE"}}} |
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
;; this is a test of https://github.com/raquo/Airstream#frp-glitches | |
;; with my rules engine: https://github.com/oakes/odoyle-rules | |
;; | |
;; run `clj -M glitch.clj` and it will print: | |
;; | |
;; [-2 false] | |
;; [2 true] | |
(require '[odoyle.rules :as o]) | |
(def rules | |
(o/ruleset | |
{::is-positive | |
[:what | |
[::number ::any any-num] | |
:then | |
(o/insert! ::number ::positive? (pos? any-num))] | |
::doubled-numbers | |
[:what | |
[::number ::any any-num] | |
:then | |
(o/insert! ::number ::doubled (* 2 any-num))] | |
::combined | |
[:what | |
[::number ::positive? positive?] | |
[::number ::doubled doubled] | |
:then | |
(o/insert! ::number ::combined [doubled positive?])] | |
::print-combined | |
[:what | |
[::number ::combined combined] | |
:then | |
(println combined)]})) | |
(def session | |
(-> (reduce o/add-rule (o/->session) rules) | |
(o/insert ::number ::any -1) | |
o/fire-rules | |
(o/insert ::number ::any 1) | |
o/fire-rules)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment