malli

2026-04-01T15:29:26.641349Z

I want to "get back" from a value to its schema. lets say I have: a valid instance of Address:

{:id "H7",
 :tags #{:v?.w.t6!.QJYk-/-?s*4
         :_7U
         :QdG/Xi8J
         :*Q-.p*8*/n-J9u}
 :address {:street "V9s"
           :city ""
           :zip 3
           :lonlat [-2.75 -0.625]}}
How can I find(programaticaly) the "schema" of :longlat for example. -> should tell me '[:tuple :double :double]' (when knowing that it is from the schema Address, defined as:
(def Address
  [:map
   [:id :string]
   [:tags [:set :keyword]]
   [:address
    [:map
     [:street :string]
     [:city :string]
     [:zip :int]
     [:lonlat [:tuple :double :double]]]]])

opqdonut 2026-04-09T14:55:44.841929Z

This is how you can access sub-schemas:

user=> (mu/get-in Address [:address :lonlat])
[:tuple :double :double]

opqdonut 2026-04-09T14:58:36.772829Z

For your use case you might want to iterate over subschemas using something like mu/subschemas or m/children

2026-04-01T15:34:22.642979Z

my overall goal is to programmitcaly "compare two adresses", and the way to compare each "leave value" depends on its "type". (two strings/keywords get compared differently then two :enum values)

2026-04-02T00:50:31.975279Z

I happen to be experimenting with something similar, does this look helpful? https://github.com/frenchy64/malli/blob/f15d235ff9aaaf35583b34f1001f294090ca5ad9/test/malli/shrinker_test.cljc#L431

2026-04-02T00:54:06.636319Z

here's one way to use it to write a diff algorithm that tells you which schema differs https://github.com/frenchy64/malli/blob/f15d235ff9aaaf35583b34f1001f294090ca5ad9/test/malli/shrinker_test.cljc#L291-L317

2026-04-02T00:55:45.580059Z

I'm mentioning this not because you should use it yet, but more because I haven't found anything generic enough for this so I'm building my own.

2026-04-01T18:35:36.593119Z

I was steering for 2 hours to two "equal vectors", which looked equal, but "=" compared them as false. And then I printed the class... (-> call-result (get [:domain] :annotation) :schema class) ;;=> malli.core$enumschema$reify$reify__13444 (-> fixed (get [:domain] :annotation) :schema class) ;;=> clojure.lang.PersistentVector So something in malli "prints like a vector" but is not comparing as a vector.

2026-04-01T18:45:27.005299Z

It happens when using mali/walk The schema in the call-back fn, is (for :enum) at least of this reify type, which "looks like a vector", but is not. ; :schema [:enum :de :fr :it] :schema-class malli.core$enumschema$reify$reify__13444 ; :schema [:enum :cold :hot :warm :cool] :schema-class malli.core$enumschema$reify$reify__13444

2026-04-01T18:47:32.297639Z

I think I was assuming, that this is true, but's its not: (= [:enum :a] (m/schema [:enum :a])) -> false

juhoteperi 2026-04-01T19:18:59.469759Z

schema returns a Schema instance (given a Schema form or a Schema instance form return a Schema form (i.e. the data representation of a schema)

2026-04-01T19:22:00.869839Z

Yes, I was just surprised, as I am new to malli, that a malli schema does not "=" to its "form" representation, and that even two schemas from the same vector are not "=" (as they print equal) Now I know it.

2026-04-01T19:24:35.475309Z

Maybe teh docu could be more explicit abou it, that

(= :string (m/schema :string)) -> false
(= :string (m/form (m/schema :string))) -> true

➕ 1