malli 2024-08-09

I have a spec something like this, specifying constraints on individual map entries and also on the relationships between different values in the map:

(def RelationshipBetweenXAndY
  [:fn
   {:error/message "bad relationship"}
   (fn [{:keys [x y]}]
     (= x y))])

(def MySpec
  [:and
   [:map
    [:x :int]
    [:y :int]]
   RelationshipBetweenXAndY])
Is there a way to modify this so that the RelationshipBetweenXAndY part is only checked if the first part of the :and gives no errors?

validation short-circuits already on first failing, right? This has been talked earlier, there might be issue about taking just first error from :and.

> validation short-circuits already on first failing, right? Exactly. I found the discussion you mentioned at https://github.com/metosin/malli/issues/1001 AFAICT, it’s not possible to short-circuit at the moment.

Another random Malli question: is there a way to annotate a schema to supply the generator with a fn to run to generate that element? or another means to achieve specifying a fn for the generator?

duh its right in the readme πŸ˜…

It's getting long!

πŸ™‚ 2

At least its long because it actually covers a lot of ground and not long for purely editorial reasons!

βž• 2

then to figure out how to make a generator, turns out you can just :gen/gen (gen/elements coll-of-values)) to generate one from random.. which is good enough to get me unstuck πŸ™‚

nice, there's sugar for that too :gen/elements