1. Meikel Brandmeyer
  2. monad


Meikel Brandmeyer  committed bc7298b

Added lift for function application

* monad.clj (lift): new macro

  • Participants
  • Parent commits f6f5b7e
  • Branches default

Comments (0)

Files changed (1)

File src/de/kotka/monad.clj

View file
  • Ignore whitespace
     (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))))