malli

2026-06-12T15:54:57.789819Z

i'm experimenting with :multi schemas, and i'd like for it to be extensible like clojure multimethods are. i have built something janky but i'm not sure if it's the best way to do it. anyone have tips/ideas for this? (here's the bare minimum example, with all the details changed cuz work stuff)

(def registry (atom {}))
(defn register-method
  [kw kv & kvs]
  (swap! registry assoc kw (m/schema `[:map [:type :keyword] ~@(cons kv kvs)])))

(register-method :client [:username :string])
(register-method :special-client [:username :string] [:status [:enum :cool :ugly]])

(def Client
  (m/schema
    `[:multi {:dispatch :type}
       ~@@registry]))

(m/validate Client {:type :client :username "Noah Bogart"}) ;; => true
(m/validate Client {:type :special-client :username "Noah Bogart" :status :weird}) ;; => false