wondering if this is a bug, took me a while to figure out at least, code in ๐งต
(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
) ;; {} ??
strip-extra-keys-transformer should probably not touch map-of?
I think there have been some surprises related to this topic before as well
Hi Joel! Hope all is well
hi, all good here ๐
so Tommi's slightly cryptic message in that issue is that this is the current behaviour, but we should probably have something else...
you might be able to dissoc :map-of from strip-extra-keys-transformer as a workaround
๐ yeah I got that. dropping the encoders/decoders for map-of will solve my use case, so I think I'll just inline that
what was your expectation? strip-extra-keys not doing anything to :map-of ?
yes
I'll write that down in the issue, it's a good data point
the point being that they are not removed if the val schema validates
(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?yes
so strip-extra-keys-transformer is really strip-key-value-pairs-that-don't-match-schema
that name would indeed have been clearer ๐
and that's not quite the right name: for :map it only looks at keys, for :map-of it looks at key-value-pairs
I guess that's actually the root of the surprise here
agree