Last active
December 20, 2015 22:49
-
-
Save jebberjeb/6208025 to your computer and use it in GitHub Desktop.
Wrap a java method call for easy use w/ map, filter, etc using a macro. memfn obviates this mess.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro ->j-fn [j-fn] | |
(let [args (gensym "args")] | |
`(fn [~args] | |
(eval (cons '~j-fn (if (coll? ~args) ~args (list ~args))))))) | |
;trivial | |
((->j-fn .length) "foo") | |
;useful, since you can't do (map .length ["foo" "bar"]) | |
(map (->j-fn .length) ["foo" "bar"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment