malli 2024-08-29

hello - I've having trouble understanding how merge and multi work. specifically when I run the example on github it just returns the last schema, there is no merging.

I’m so excited about this! Thanks so much to @ambrosebs for making merge and multi work like how I hoped they would 🙂

❤️ 1

I think there have been several issues and questions in the past regarding simplification and this is fundamental and a good addition to malli. All schemas should know how to generically express conjunction or disjunction

Ideally we'd want some symbolic eval for malli schemas

[:and :int [:<= 5]] => [:int {:min 5}]

I had a prototype of this a few years ago, but here's a transformation that could also be useful for negating schemas. https://github.com/frenchy64/malli/pull/4/files#diff-9f5ce127b24a172f70188161d9c355f41891bfa64fa107800d6fb7389e2b23cb

[:not [:int {:< 5}] => [:int {:>= 5}}

cljs bundle size seems to be the biggest hurdle here.

this is what I see vs what github says I should see.

; metosin/malli {:mvn/version "0.16.3"}  
  (require '[malli.core :as m])
  (require '[malli.util :as mu])
  (def registry (merge (m/default-schemas) (mu/schemas)))

;; left-distributive
  (m/deref
   [:merge
    [:map [:x :int]]
    [:multi {:dispatch :y}
     [1 [:map [:y [:= 1]]]]
     [2 [:map [:y [:= 2]]]]]]
   {:registry registry})
  ; => [:multi {:dispatch :y} [1 [:map [:y [:= 1]]]] [2 [:map [:y [:= 2]]]]]
  
  ;; right-distributive
  (m/deref
   [:merge
    [:multi {:dispatch :y}
     [1 [:map [:y [:= 1]]]]
     [2 [:map [:y [:= 2]]]]]
    [:map [:x :int]]]
   {:registry registry})
  ; => [:map [:x :int]]

oh just found https://github.com/metosin/malli/pull/1086 was only merged 2 days ago, I guess this is a new feature not in 0.16.3

yea ok used the latest git sha and it works as expected 🎉

👍 1
🎉 1

I'll cut a release before sunday

💪 2

Can't believe I slept on this MR, this is huge

From Github --- “For performance, it’s best to prebuild the validator, decoder and explainer”. Is there one for “pretty”? I only see “pretty/explain”.

no, there is no pretty/explainer.

But, there is m/coercer which can emits pretty errors when malli.dev/start! is enabled. Not exactly same (throws errors instead of returning the explanation)

1