Skip to content

Instantly share code, notes, and snippets.

@RickMoynihan
Last active January 4, 2017 09:58
Show Gist options
  • Save RickMoynihan/96a0556116106e4e3c4356f99198a815 to your computer and use it in GitHub Desktop.
Save RickMoynihan/96a0556116106e4e3c4356f99198a815 to your computer and use it in GitHub Desktop.
(defmulti foo identity)
(defmethod foo :foo [_] :foo)
(defmethod foo :bar [_] :bar)
(derive :foo-child :foo)
(derive :bar-child :bar)
(defn supported-parameter?
"Predicate function that returns true if the parameter type is
supported by grafter-server. Supported parameters are types which
supported either explicitly via the parse-parameter multimethod or
through this multimethods type hierarchy."
[p]
(some (partial isa? p)
(keys (methods foo))))
(defn parameter-type-chain
"Interogates the parse-parameter multi-method and returns an ordered
sequence representing the "
[t]
(when (supported-parameter? t)
(let [ps (parents t)]
(cons t (lazy-seq (mapcat parameter-type-chain ps))))))
(defn supported-parameter-types
"Returns the set of currently supported parameter-types"
[]
(->> (methods foo)
keys
(mapcat parameter-type-chain)
set))
(comment
(parameter-type-chain :foo-child) ;; => (:foo-child :foo)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment