Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Mar 30, 2024

Conversation

frenchy64
Copy link
Contributor

@frenchy64 frenchy64 commented Mar 14, 2024

Related #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

@frenchy64 frenchy64 changed the title WIP: mx/defn destructuring => spec problem Use :multi instead of :altn for map destructuring Mar 14, 2024
@frenchy64 frenchy64 marked this pull request as ready for review March 14, 2024 03:30
@frenchy64 frenchy64 changed the title Use :multi instead of :altn for map destructuring Use :orn instead of :altn for map destructuring Mar 14, 2024
@frenchy64 frenchy64 changed the title Use :orn instead of :altn for map destructuring [Demo] Use :orn instead of :altn for map destructuring Mar 14, 2024
@frenchy64 frenchy64 marked this pull request as draft March 14, 2024 04:21
@frenchy64 frenchy64 changed the title [Demo] Use :orn instead of :altn for map destructuring [Feedback wanted] Use :orn instead of :altn for map destructuring Mar 22, 2024
@ikitommi
Copy link
Member

makes sense!

@frenchy64 frenchy64 force-pushed the mx-defn-destructure branch 2 times, most recently from fdf3fa4 to ead1d01 Compare March 23, 2024 14:31
@frenchy64 frenchy64 changed the title [Feedback wanted] Use :orn instead of :altn for map destructuring Use :orn instead of :altn for map destructuring Mar 23, 2024
@frenchy64 frenchy64 marked this pull request as ready for review March 23, 2024 14:36
@jasonjckn
Copy link
Contributor

+1

@ikitommi ikitommi merged commit 2bdc1cf into metosin:master Mar 30, 2024
9 checks passed
@ikitommi
Copy link
Member

Good catch, thanks!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants