malli
malli copied to clipboard
schema inference from source code
Schema providers can take sample input and generate a schema. How magical would it be if one could infer a schema from code?
(defn-magic foo [m] (+ (:x m) (-> m :y :yy)))
;; => [:map [:x number?] [:y [:map [:yy number?]]]]
I think this could be done by code-walking or something similar. If done right I think this would be invaluable, we'd get type-inference-like capabilities in the language :)
Tools like clj-kondo and core.typed are both actively developed, I think this falls into scope of those libs. Plan is to integrate malli with clj-kondo later anyway.
clj-kondo integration might be quite a killer feature!
WIP.

Apparently Typed Clojure can automagically infer Specs.
malli.typed ?
Unfortunately, Typed Clojure can only infer specs from data (not code), like malli does :) It instruments your code and then runs your tests.
It does some fancy things around deciding whether something is a multispec, but that's about it.