# Malli union not doing what im hoping

**URL:** https://clojureverse.org/t/malli-union-not-doing-what-im-hoping/10591
**Category:** General Questions
**Created:** [February 18, 2024, 4:10pm UTC](https://clojureverse.org/t/malli-union-not-doing-what-im-hoping/10591 "2024-02-18T16:10:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Henrik\_Larsson](https://clojureverse.org/user_avatar/clojureverse.org/henrik_larsson/32/5304_2.png) [@Henrik\_Larsson](https://clojureverse.org/u/Henrik_Larsson)
#### Post date: [February 18, 2024, 4:10pm UTC](https://clojureverse.org/t/malli-union-not-doing-what-im-hoping/10591/1 "2024-02-18T16:10:09Z")

</div>

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.

```auto
(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?

---

<div class="post-metadata">

### Author: ![p-himik](https://clojureverse.org/user_avatar/clojureverse.org/p-himik/32/4137_2.png) [@p-himik](https://clojureverse.org/u/p-himik)
#### Post date: [February 18, 2024, 5:19pm UTC](https://clojureverse.org/t/malli-union-not-doing-what-im-hoping/10591/2 "2024-02-18T17:19:31Z")

</div>

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`:

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

```

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

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

```

---

<div class="post-metadata">

### Author: ![Henrik\_Larsson](https://clojureverse.org/user_avatar/clojureverse.org/henrik_larsson/32/5304_2.png) [@Henrik\_Larsson](https://clojureverse.org/u/Henrik_Larsson)
#### Post date: [February 19, 2024, 6:20pm UTC](https://clojureverse.org/t/malli-union-not-doing-what-im-hoping/10591/3 "2024-02-19T18:20:01Z")

</div>

Nice thanks, this gave enogh information.

---

<div class="post-metadata">

### Author: ![system](https://clojureverse.org/uploads/default/original/2X/5/51079bf9e4b7d9466242c06cf1e43b9f8bd6da14.png) [@system](https://clojureverse.org/u/system)
#### Post date: [August 20, 2024, 6:20am UTC](https://clojureverse.org/t/malli-union-not-doing-what-im-hoping/10591/4 "2024-08-20T06:20:23Z")

</div>

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