[swift-users] Making Error sub-enums Equatable

Brent Royal-Gordon brent at architechies.com
Wed May 10 09:06:30 CDT 2017

> On May 10, 2017, at 2:05 AM, Rick Mann <rmann at latencyzero.com> wrote:
> This seems so obvious that I feel like it should be provided by the language by default. I suppose you can make it even more compact with
>    case (.one, .one),
>         (.two, .two),
>         (.three, .three):
> 	return true
> Maybe swift could provide a 'case==()' so one needn't write this (I can see it getting quite tedious and error-prone, should one forget to update the equality after adding additional cases).

There's been some talk on swift-evolution about synthesizing an `Equatable` implementation for enums with associated types, but that would not implement your slightly weird equality semantic—it would compare the associated types, which isn't what you want. The same would undoubtedly be true for any other syntactic sugar we might provide. So I wouldn't hold your breath waiting for a better way to implement it than this.

Brent Royal-Gordon

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170510/fb07633a/attachment.html>

More information about the swift-users mailing list