Skip to content

Instantly share code, notes, and snippets.

@mccraigmccraig
Last active August 29, 2015 14:24
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 mccraigmccraig/10fe6eeda12dc47f2850 to your computer and use it in GitHub Desktop.
Save mccraigmccraig/10fe6eeda12dc47f2850 to your computer and use it in GitHub Desktop.
yoyo with cont-m from algo.monads
(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