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?
see the :gen/* keywords in the readme: https://github.com/metosin/malli?tab=readme-ov-file#value-generation
perhaps :gen/fmap?
duh its right in the readme π
or :gen/gen
It's getting long!
At least its long because it actually covers a lot of ground and not long for purely editorial reasons!
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
even better!