malli

shane 2024-08-29T15:47:02.244529Z

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.

Ryan 2024-08-30T15:19:06.026349Z

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

❤️ 1
2024-08-30T16:22:37.430689Z

@ben.sless thoughts?

Ben Sless 2024-08-30T16:43:52.261659Z

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

Ben Sless 2024-08-30T17:53:00.312559Z

Ideally we'd want some symbolic eval for malli schemas

Ben Sless 2024-08-30T17:53:32.089519Z

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

2024-08-30T18:10:54.926229Z

yeah I think that's on the cards see this discussion https://github.com/metosin/malli/pull/1095#issuecomment-2313634014

2024-08-30T18:14:50.029999Z

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}}

2024-08-30T18:16:13.568809Z

cljs bundle size seems to be the biggest hurdle here.

shane 2024-08-29T15:47:54.141539Z

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]]

shane 2024-08-29T15:56:42.080619Z

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

shane 2024-08-29T16:00:31.429979Z

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

👍 1
🎉 1
ikitommi 2024-08-29T16:22:01.745979Z

I'll cut a release before sunday

💪 2
Ben Sless 2024-08-29T20:11:32.287109Z

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

Joel 2024-08-29T19:01:20.791399Z

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

ikitommi 2024-08-30T05:05:41.102859Z

no, there is no pretty/explainer.

ikitommi 2024-08-30T05:08:00.353219Z

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