Malli union not doing what im hoping

I have lots of rules for which I would like to generate a schema from. I have found malli union to be a good candidate but im struggling to understand how I can use it to build up a larger map schema from many small, the code I have experimented with is as follows.

(mg/generate
 (reduce mu/union [[:map
                    [:a [:map [:b [:enum 33]]]]]

                   [:map
                    [:a [:map [:b [:enum 44]  [:not [:= 33]]]]]]

                   [:map
                    [:a [:map [:b [:enum 77]]]]]]))

What I would like to express is what is the allowed values and what are the not allowed values for every key and them merge them all together to form the final domain for each key. However the code shown do not for example exclude 33 which I would expect.

What am I missing in my understanding about malli?

As far as I can tell, [:map [:b [:enum 44] [:not [:= 33]]]] is not a valid schema. Or rather, it is valid, but it doesn’t do what you think it does. That [:enum 44] becomes {:enum 44} and is completely ignored. You probably wanted to wrap it all in [:and ...].

With that being said, mu/union basically does or at the level of values, not and:

(mu/union [:map [:a integer?]]
          [:map [:a string?]])
=> [:map [:a [:or integer? string?]]]

But it does act like and at the level of values:

(mu/union [:map [:a integer?]]
          [:map [:b string?]])
=> [:map [:a integer?] [:b string?]]

Nice thanks, this gave enogh information.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.