Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
(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