malli 2025-05-14

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.

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.

šŸ‘ 1