metosin / malli

High-performance data-driven data specification library for Clojure/Script.
Eclipse Public License 2.0
1.43k stars 204 forks source link

Use `:orn` instead of `:altn` for map destructuring #1019

Closed frenchy64 closed 3 months ago

frenchy64 commented 3 months ago

Related https://github.com/metosin/malli/issues/1020

Map destructuring shouldn't convert to an :altn because it turns into a sequence spec when nested:

(malli.generator/generate
  [:map [:outer [:altn
                 [:map [:map [:inner :any]]]]]])
;=> {:outer [{:inner nil}]}

(m/validate
  [:map [:outer [:altn
                 [:map [:map [:inner :any]]]
                 [:seq [:* :any]]]]]
  {:outer {:inner "a"}})
;=> false

:orn is better for the job here:

(m/validate
  [:map [:outer [:orn
                 [:map [:map [:inner :any]]]
                 [:seq [:* :any]]]]]
  {:outer {:inner "a"}})
;=> true
ikitommi commented 3 months ago

makes sense!

jasonjckn commented 3 months ago

+1

ikitommi commented 3 months ago

Good catch, thanks!!