Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

for comprehensions as monad in clojure

View gist:4588672
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
(for [x [:a :b :c]
y [1 2 3]]
[x y])
 
 
(defn bind [mv f] (mapcat f mv))
(bind v1 (fn [x]
(bind v2 (fn [y]
(vector [x y])))))
(defmacro m-do [result
[sym1 mv1
sym2 mv2]
expression]
`(bind ~mv1 (fn [~sym1]
(bind ~mv2 (fn [~sym2]
(~result ~expression))))))
(m-do vector [x [:a :b :c]
y [1 2 3]]
[x y])
Owner

this is from Jim Duey's unsession at clojure conj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.