how can I get the input arguments given a function schema? e.g. the :int for
(m/function-schema [:=> [:cat :int] :double])
(m/function-schema [:-> :int :double])First collect all the arities with m/-function-arities. This handles [:function ...]. Then map m/-function-info over the result giving a seq of maps. :input will contain a schema of all parameter types for that arity.
(->> s m/-function-arities (map (comp :input m/-function-info))))
The schemas will be regex schemas, so the [:cat :int] in your example. I've written code in the past to go from this to :int but it can get pretty complicated supporting all kinds of regexes.
Something like this flattens regex schemas into a sequence if possible https://github.com/typedclojure/typedclojure/blob/0b3ffb01b6a943bdfe0c279cfc7aae78304bec7c/typed/malli/src/typed/malli/schema_to_type.cljc#L16-L49
i.e., transforms [:cat :int] into (:int).
A starting point for the most common case could be something like:
(defn input->list [s]
(case (m/type s)
:cat (mapcat input->list (m/children s))
(if (m/-regex-op? s)
(throw (ex-info "Unsupported" {}))
[s])))so all up:
(->> s m/-function-arities (map (comp input->list :input m/-function-info)))I didn't test all this, lmk how it goes.
@ambrosebs thanks you! Iām currently afk but will try this in a bit and let you know.