Created
May 12, 2020 02:19
-
-
Save staypufd/9284d6494c90c28ef0c76d7a28863bff to your computer and use it in GitHub Desktop.
Managing Conditions across functions boundaries
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
```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