# Nested tagged unions

**URL:** <https://ziggit.dev/t/nested-tagged-unions/6173>\
**Category:** Help\
**Tags:** language, standard-library\
**Created:** [September 28, 2024, 7:30am UTC](https://ziggit.dev/t/nested-tagged-unions/6173 "2024-09-28T07:30:53Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Sze](https://ziggit.dev/user_avatar/ziggit.dev/sze/32/496_2.png) [@Sze](https://ziggit.dev/u/Sze)\
**Post date:** [September 28, 2024, 11:00am UTC](https://ziggit.dev/t/nested-tagged-unions/6173/5 "2024-09-28T11:00:52Z")

</div>

I think you want something more like this:

```zig
switch (this.q) { // not tag(this.q)
    inline else => |u, tag|
        return u == @field(other.q, @tagName(tag)),
}

```

related topic:

> [@Union Equality](https://ziggit.dev/t/union-equality/4060/7):
>
> I think this is kind of neat: pub fn equals(self: Value, other: Value) bool { return switch (self) { inline else =\> |value, tag| tag == std.meta.activeTag(other) and value == @field(other, @tagName(tag)), }; } This works because for nil it just compares that {} is equal to {} which is true. If any case should compare values differently like for example float, you can add it as an explicit case like this: pub fn equals(self: Value, other: Value) bool {…

---

_[View the full topic](https://ziggit.dev/t/nested-tagged-unions/6173)._
