Skip to content

Instantly share code, notes, and snippets.

@staypufd
Created May 12, 2020 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save staypufd/9284d6494c90c28ef0c76d7a28863bff to your computer and use it in GitHub Desktop.
Save staypufd/9284d6494c90c28ef0c76d7a28863bff to your computer and use it in GitHub Desktop.
Managing Conditions across functions boundaries
```clojure
(ns specialdemo.core
(:require [special.core :refer [condition manage]])
(:gen-class))
(defn fizz-buzz [i]
(let [f (fn [n]
(for [i (range n)]
(cond
(and (= (mod i 3) 0)
(= (mod i 5) 0))
(condition :fizzbuzz "fizzbuzz")
(= (mod i 3) 0)
(condition :fizz "fizz")
(= (mod i 5) 0)
(condition :buzz "buzz")
:else i
)))
;g (manage f
; :fizzbuzz identity
; :fizz identity
; :buzz identity)
]
(f i)))
(defn fizzbuzz []
(let [fizzbuzz-manager (manage fizz-buzz
:fizzbuzz identity
:fizz identity
:buzz identity)]
(prn (fizzbuzz-manager 10)))
)
(defn -main
"I don't do a whole lot ... yet."
[& args]
(println "Hello, World!")
(fizzbuzz)
)
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment