Created
August 16, 2025 11:52
-
-
Save niw/31623f57efbbe2f357f6fee47362fab0 to your computer and use it in GitHub Desktop.
A non-nominal, structual Tuple that conforms Equatable.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| // Tuple.swift | |
| // Tuple | |
| // | |
| // Created by Yoshimasa Niwa on 8/8/25. | |
| // | |
| public struct Tuple<each T: Equatable>: Equatable { | |
| public static func == (lhs: Tuple<repeat each T>, rhs: Tuple<repeat each T>) -> Bool { | |
| var result = true | |
| func compare<U: Equatable>(lhs: U, rhs: U) { | |
| if !result { | |
| return | |
| } | |
| result = lhs == rhs | |
| } | |
| repeat compare(lhs: each lhs.values, rhs: each rhs.values) | |
| return result | |
| } | |
| public var values: (repeat each T) | |
| public init(_ values: repeat each T) { | |
| self.values = (repeat each values) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment