Skip to content

Instantly share code, notes, and snippets.

@jebberjeb
Last active December 20, 2015 22:49
Show Gist options
  • Save jebberjeb/6208025 to your computer and use it in GitHub Desktop.
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.
(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