Skip to content

Instantly share code, notes, and snippets.

@jarpiain
Created October 7, 2010 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarpiain/615573 to your computer and use it in GitHub Desktop.
Save jarpiain/615573 to your computer and use it in GitHub Desktop.
(defmacro currying-fn [args & body]
`(fn
(~args ~@body)
~@(for [i (next (range (count args)))]
(let [[head tail] (split-at i args)]
`(~(vec head) (currying-fn ~(vec tail) ~@body))))))
(def apply-if (currying-fn [p f x] (if (p x) (f x) x)))
(map (apply-if odd? inc) (range 10))
--> (0 2 2 4 4 6 6 8 8 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment