malli

hanDerPeder 2026-01-08T14:04:50.800059Z

wondering if this is a bug, took me a while to figure out at least, code in ๐Ÿงต

hanDerPeder 2026-01-08T14:05:03.228039Z

(def Thing
    [:map 
     [:x :int]
     [:y :string]])

  (def Lookup
    [:map-of :int Thing])

  (def things (map #(array-map :x % :y (str %)) (range 10)))

  (malli.core/validate 
   Lookup
   (into {} (map (juxt :x identity)) things)) ;; true

  (def bad-things (map #(array-map :x %) (range 10)))

  (malli.core/validate 
   Lookup
   (into {} (map (juxt :x identity)) bad-things)) ;; false

  (malli.core/coerce
   Lookup
   (into {} (map (juxt :x identity)) bad-things)) ;; throws

  ;; So far so good, but

  (malli.core/coerce
   Lookup
   (into {} (map (juxt :x identity)) bad-things)
   malli.transform/strip-extra-keys-transformer
   ) ;; {} ??

hanDerPeder 2026-01-08T14:06:22.380769Z

strip-extra-keys-transformer should probably not touch map-of?

opqdonut 2026-01-08T14:06:43.013909Z

I think there have been some surprises related to this topic before as well

hanDerPeder 2026-01-08T14:07:18.853089Z

Hi Joel! Hope all is well

opqdonut 2026-01-08T14:07:23.571629Z

https://github.com/metosin/malli/issues/1118

opqdonut 2026-01-08T14:08:03.465599Z

hi, all good here ๐Ÿ™‚

opqdonut 2026-01-08T14:08:59.473699Z

so Tommi's slightly cryptic message in that issue is that this is the current behaviour, but we should probably have something else...

opqdonut 2026-01-08T14:09:41.059959Z

you might be able to dissoc :map-of from strip-extra-keys-transformer as a workaround

๐ŸŽฏ 1
hanDerPeder 2026-01-08T14:09:43.221909Z

๐Ÿ™‚ yeah I got that. dropping the encoders/decoders for map-of will solve my use case, so I think I'll just inline that

opqdonut 2026-01-08T14:10:40.590519Z

what was your expectation? strip-extra-keys not doing anything to :map-of ?

hanDerPeder 2026-01-08T14:11:16.228269Z

yes

opqdonut 2026-01-08T14:11:45.176869Z

I'll write that down in the issue, it's a good data point

โค๏ธ 1
hanDerPeder 2026-01-08T14:17:50.279189Z

the point being that they are not removed if the val schema validates

hanDerPeder 2026-01-08T14:19:17.025519Z

(malli.core/coerce
   Lookup
   (into {} (map (juxt :x identity)) things)
   mt/strip-extra-keys-transformer) ;;{0 {:x 0 ...
so they are only extra if the value is bad?

opqdonut 2026-01-08T14:33:02.861009Z

yes

opqdonut 2026-01-08T14:33:56.613019Z

so strip-extra-keys-transformer is really strip-key-value-pairs-that-don't-match-schema

hanDerPeder 2026-01-08T14:34:55.771429Z

that name would indeed have been clearer ๐Ÿ˜„

opqdonut 2026-01-08T14:35:34.098059Z

and that's not quite the right name: for :map it only looks at keys, for :map-of it looks at key-value-pairs

opqdonut 2026-01-08T14:35:46.384079Z

I guess that's actually the root of the surprise here

hanDerPeder 2026-01-08T14:36:05.236999Z

agree