malli 2025-01-13

Proposing some new schemas to increase expressivity of map keysets https://github.com/metosin/malli/pull/1161

;; if :git/tag is provided, then so should :git/sha
(def TagImpliesSha
  [:and
   [:map
    [:git/sha {:optional true} :string]
    [:git/tag {:optional true} :string]]
   [:implies [:has :git/tag] [:has :git/sha]]])

(m/validate TagImpliesSha {:git/sha "abc123"}) ;=> true
(m/validate TagImpliesSha {:git/tag "v1.0.0" :git/sha "abc123"}) ; => true

(me/humanize
  (m/explain TagImpliesSha {:git/tag "v1.0.0"}))
; => {:git/sha ["missing required key"]}

👍 2
👀 1
🎉 2

This is amazing. The virtue of being "open to changes" often results in this kind of implicit rules. I think I'm going to use this a lot once this PR is merged.

❤️ 1
➕ 1

btw I'll probably talk about this during this podcast (live soon) https://www.youtube.com/watch?v=VG8nu55bpts

didn't talk too much about it in the end, was nerd sniped into explaining transducers

🤣 1

hey, finally time to look for this (and others).

@ikitommi thanks! I'll let you know when the next iteration is ready.

👍 1