Created
October 30, 2010 02:46
-
-
Save astrangeguy/654851 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
user> (map #(has-arity? (fn
([])
([a b])
([a b c d & e]))
%)
[0 1 2 3 4 5 6 7 8 9 10])
(true false true false true true true true true true true)