Last active
August 29, 2015 13:56
-
-
Save cursork/9088936 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(defn arities | |
"Returns the possible arities of a function implementing ifn. For want of | |
anything better to return for a variadic 'rest function', returns | |
nil." | |
[ifn] | |
{:pre [(ifn? ifn)]} | |
(let [invokes (filter #(= (.getName %) "invoke") (.getDeclaredMethods (class ifn))) | |
arity #(count (.getParameterTypes %))] | |
(if (instance? clojure.lang.RestFn ifn) | |
'(nil) | |
(map arity invokes)))) | |
(defn has-arity? | |
[ifn arity] | |
(when (some #(= % arity) (arities ifn)) | |
true)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment