Skip to content

Instantly share code, notes, and snippets.

@megakorre
Created July 18, 2012 18:43
Show Gist options
  • Save megakorre/3137983 to your computer and use it in GitHub Desktop.
Save megakorre/3137983 to your computer and use it in GitHub Desktop.
functional interface implementation in clojure
(defmacro fi
[interface args & code]
(let [interface-type (.getMapping *ns* interface)
methods (-> (.getMethods interface-type)
seq)
method-sym (.getName (first methods))]
(when-not (= (count methods) 1)
(throw (new Exception "cant take a interface with more then one method")))
`(proxy [~interface] []
(~method-sym ~args
~@code))))
(comment
(import java.awt.event.ActionListener)
(def action (fi ActionListener [e]
(println "hello world"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment