Skip to content

Instantly share code, notes, and snippets.

@dterekhov
Last active October 24, 2025 07:36
Show Gist options
  • Select an option

  • Save dterekhov/94896ef6895d41a19616561be0b91519 to your computer and use it in GitHub Desktop.

Select an option

Save dterekhov/94896ef6895d41a19616561be0b91519 to your computer and use it in GitHub Desktop.
Don't create small structures, use Structural types #tip #swift-api
// Demonstrates that tuple type aliases with identical structures are considered equal by Swift.
typealias Person = (name: String, age: Int)
typealias Address = (street: String, houseNumber: Int)
let abbey = Person(name: "Abbey Road", age: 29)
let home = Address(street: "Abbey Road", houseNumber: 29)
if abbey == home {
print("They are structurally equal!") // Works!
}
@dterekhov
Copy link
Author

E7237267-815C-4604-A6FE-B0B72F94F8BB_1_105_c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment