Last active
August 29, 2015 14:04
-
-
Save sordina/6b9faec46bb6f2352ce0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(deftype PromiseWrapper [r fun prom] | |
clojure.lang.IDeref | |
(deref [this] | |
(dosync | |
(let [current @r] | |
(if current (:value current) | |
(let [result (fun @prom)] | |
(ref-set r {:value result}) | |
result)))))) | |
(defmacro fmap [fun prom] | |
`(PromiseWrapper. (ref nil) ~fun ~prom)) | |
(defmacro then [a b & body] | |
`(fmap (fn [r#] (let [~b r#] ~@body)) ~a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment