Last active
August 29, 2015 14:24
-
-
Save mccraigmccraig/f5305e4e30845d12333e to your computer and use it in GitHub Desktop.
yoyo with cont-m
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 '[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