Commits

Meikel Brandmeyer committed bc7298b

Added lift for function application

* monad.clj (lift): new macro

  • Participants
  • Parent commits f6f5b7e

Comments (0)

Files changed (1)

src/de/kotka/monad.clj

     (if (nil? clauses)
       `(bind ~monad (fn [~v] ~@body))
       `(bind ~monad (fn [~v] (let-bind ~clauses ~@body))))))
+
+(defmacro lift
+  "Call the given function f with the values of all given monads in the
+  same order. f should again return a monad."
+  [f & ms]
+  (let [xs (take (count ms) (drop 1 (iterate gensym "lift__")))]
+    `(let-bind ~(vec (interleave xs ms)) (~f ~@xs))))