Skip to content

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

Merged
ikitommi merged 1 commit into
metosin:masterfrom
frenchy64:mx-defn-destructure
Mar 30, 2024
Merged

Use :orn instead of :altn for map destructuring#1019
ikitommi merged 1 commit into
metosin:masterfrom
frenchy64:mx-defn-destructure

Conversation

@frenchy64

@frenchy64 frenchy64 commented Mar 14, 2024

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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 force-pushed the mx-defn-destructure branch from ead1d01 to ce586a6 Compare March 23, 2024 14:34
@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
Copy Markdown
Contributor

+1

@ikitommi ikitommi merged commit 2bdc1cf into metosin:master Mar 30, 2024
@ikitommi

Copy link
Copy Markdown
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.

3 participants