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/f5305e4e30845d12333e to your computer and use it in GitHub Desktop.
Save mccraigmccraig/f5305e4e30845d12333e to your computer and use it in GitHub Desktop.
yoyo with cont-m
(require '[cats.core :refer :all])
(require '[cats.monad.continuation :as cont])
(defn with-something
[config]
(cont/continuation
(fn [cc]
(prn (str "setting up something: " (pr-str config)))
(let [r (cc :something)]
(prn "tearing down something")
r))))
(defn with-other-thing
[config]
(cont/continuation
(fn [cc]
(prn (str "setting up other-thing: " (pr-str config)))
(let [r (cc :other-thing)]
(prn "tearing down other-thing")
r))))
(def s (mlet [config (return cont/continuation-monad {:foo 10})
a (with-something config)
b (with-other-thing (merge config {:bar a}))]
(return cont/continuation-monad [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