metosin / malli

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

Utility to update entry properties: update-entry-properties #1037

Closed frenchy64 closed 2 months ago

frenchy64 commented 2 months ago

This is what I came up with to answer this slack question: https://clojurians.slack.com/archives/CLDK6MFMK/p1712696483105789

ikitommi commented 2 months ago

well, I can do those. merging. thanks!

ikitommi commented 2 months ago

https://github.com/metosin/malli/commit/48544d533bf700151c886c13064c29a916a69fa9?w=1

ikitommi commented 2 months ago
(mu/find [:map [:x :int]] :x) 
; => [:x nil :int]
frenchy64 commented 2 months ago

Thanks! I was trying to reverse engineer this line, tbh I still don't understand it. https://github.com/metosin/malli/blob/48544d533bf700151c886c13064c29a916a69fa9/src/malli/core.cljc#L360

ikitommi commented 2 months ago

mu/find wraps the search key into a vector of [::m/find key], m/-get-entries unwraps it and returns the full entry instead of just the value behind the key. Entries are still always of size 3.

(m/-get-entries (m/schema [:map [:x :int]]) :x nil)
; => :int

(m/-get-entries (m/schema [:map [:x :int]]) [::m/find :x] nil)
; => [:x nil :int]