Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
for comprehensions as monad in clojure
(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

dustingetz commented Mar 7, 2013

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