malli icon indicating copy to clipboard operation
malli copied to clipboard

Add `-walk` option to inherit `::val` properties

Open frenchy64 opened this issue 1 year ago • 3 comments

Problem: during a -walk, it's useful for the props of ::val nodes to be inherited by the :map/:or/:multi entry. Currently this is difficult to implement.

This simplifies walk-properties in the documentation, but I'm not sure it's airtight enough to release as more than a suggestion.

I considered reusing ::walk-entry-vals but it could be a breaking change.

frenchy64 avatar Aug 16 '24 22:08 frenchy64

Had to revisit how the entry walking works, this is not good:

(defn walk [schema]
  (m/walk
   schema
   (m/schema-walker identity)
   {::m/walk-entry-vals true}))

(-> [:map [:x :int]] (walk) (walk) (walk))
; [:map [:x [:malli.core/val [:malli.core/val [:malli.core/val :int]]]]]

I guess the right thing to do would be to do automatically the opposite unwrapping somewhere. Where? in the m/schema-walker?

ikitommi avatar Aug 27 '24 14:08 ikitommi

I guess the right thing to do would be to do automatically the opposite unwrapping somewhere.

Yes, I noticed the same thing.

Where? in the m/schema-walker?

I think it would reasonable for -inner-entries to collapse any ::val schemas it finds on the way back up.

frenchy64 avatar Aug 27 '24 20:08 frenchy64

I considered reusing ::walk-entry-vals but it could be a breaking change.

I think it's a bug that the entries are kept after walking, so it would be ok to to de-walk them using ::walk-entry-vals. It's a breaking change, but for the better.

ikitommi avatar Mar 26 '25 08:03 ikitommi