Last active
August 29, 2015 14:24
-
-
Save mccraigmccraig/10fe6eeda12dc47f2850 to your computer and use it in GitHub Desktop.
yoyo with cont-m from algo.monads
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
(require '[clojure.algo.monads :refer :all]) | |
(defn with-something | |
[config] | |
(fn [cc] | |
(prn (str "setting up something: " (pr-str config))) | |
(let [r (cc :something)] | |
(prn "tearing down something") | |
r))) | |
(defn with-other-thing | |
[config] | |
(fn [cc] | |
(prn (str "setting up other-thing: " (pr-str config))) | |
(let [r (cc :other-thing)] | |
(prn "tearing down other-thing") | |
r))) | |
(def s (domonad | |
cont-m | |
[config (m-result {:foo 10}) | |
a (with-something config) | |
b (with-other-thing (merge config {:bar a}))] | |
[config a b])) | |
(def p (promise)) | |
(def r (future | |
(s (fn [v] (prn (str "running system with: " (prn-str v))) (deref p))))) | |
(deliver p :hi!) | |
@p |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment