malli

mkvlr 2025-05-14T09:07:03.619029Z

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])

2025-05-14T16:07:46.404949Z

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.

2025-05-14T16:08:37.126039Z

(->> s m/-function-arities (map (comp :input m/-function-info))))

2025-05-14T16:10:12.529029Z

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.

2025-05-14T16:13:41.502919Z

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

2025-05-14T16:14:16.424649Z

i.e., transforms [:cat :int] into (:int).

2025-05-14T16:19:55.015179Z

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])))

2025-05-14T16:22:12.365159Z

so all up:

(->> s m/-function-arities (map (comp input->list :input m/-function-info)))

2025-05-14T16:22:44.573619Z

I didn't test all this, lmk how it goes.

mkvlr 2025-05-14T16:52:53.553619Z

@ambrosebs thanks you! I’m currently afk but will try this in a bit and let you know.

šŸ‘ 1