Skip to content

Instantly share code, notes, and snippets.

@amalloy
Created December 6, 2011 22:19
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 amalloy/1440296 to your computer and use it in GitHub Desktop.
Save amalloy/1440296 to your computer and use it in GitHub Desktop.
(defmacro real-varargs [method required-count]
(let [args (repeatedly (inc required-count) gensym)]
`(let [f# (fn [~@args]
(~method ~@args))]
(fn [& args#]
(let [[before# after#] (split-at ~required-count args#)]
(apply f# `(~@before# ~(into-array after#))))))))
(def add-all (real-varargs java.util.Collections/addAll 1))
user> (seq (doto (java.util.ArrayList.) (add-all "10" "20")))
("10" "20")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment