Created
October 30, 2010 02:38
-
-
Save astrangeguy/654841 to your computer and use it in GitHub Desktop.
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
(ns strangeness.fn-arity | |
(:import java.lang.reflect.Method)) | |
(defn declared-methods [^Class class] | |
(filter #(= class (.getDeclaringClass ^Method %)) | |
(.getMethods class))) | |
(defn has-arity? [fun arity] | |
(let [cls (class fun) | |
methods (declared-methods cls)] | |
(or (when (instance? clojure.lang.RestFn fun) | |
(<= (.getRequiredArity ^clojure.lang.RestFn fun) arity)) | |
(boolean (some (fn [^Method m] | |
(and (= "invoke" (.getName m)) | |
(= (count (.getParameterTypes m)) arity))) | |
methods))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment