Skip to content

Instantly share code, notes, and snippets.

@niw
Created August 16, 2025 11:52
Show Gist options
  • Select an option

  • Save niw/31623f57efbbe2f357f6fee47362fab0 to your computer and use it in GitHub Desktop.

Select an option

Save niw/31623f57efbbe2f357f6fee47362fab0 to your computer and use it in GitHub Desktop.
A non-nominal, structual Tuple that conforms Equatable.
//
// 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