Skip to content

Instantly share code, notes, and snippets.

@cursork
Last active August 29, 2015 13:56
Show Gist options
  • Save cursork/9088936 to your computer and use it in GitHub Desktop.
Save cursork/9088936 to your computer and use it in GitHub Desktop.
(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