malli

2024-08-09T10:09:55.528959Z

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?

ikitommi 2024-08-09T12:51:56.329469Z

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

2024-08-09T17:55:14.500859Z

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

Ryan 2024-08-09T16:54:28.202009Z

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?

2024-08-09T16:55:43.352349Z

see the :gen/* keywords in the readme: https://github.com/metosin/malli?tab=readme-ov-file#value-generation

2024-08-09T16:56:14.055259Z

perhaps :gen/fmap?

Ryan 2024-08-09T16:56:30.642809Z

duh its right in the readme πŸ˜…

2024-08-09T16:56:32.882009Z

or :gen/gen

2024-08-09T16:57:02.676839Z

It's getting long!

πŸ™‚ 2
Ryan 2024-08-09T16:58:13.352649Z

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

βž• 2
Ryan 2024-08-09T17:31:01.912189Z

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 πŸ™‚

2024-08-09T17:37:28.018739Z

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

Ryan 2024-08-09T17:44:29.259229Z

even better!