Protocol Conformance for Tuples / Anonymous Structs

this is getting to the actual root of the problem. i’ve felt for a while now that when people ask for tuple conformances, what they really want is to define a struct but use the tuple syntax to express it, since tuples in swift are really pretty feature-poor (no splats!) so there’s only two possible reasons you’d want to use one:

  • you want the () syntax (“why do i have to spell my Point3D with .init()?”)
  • you’re too lazy to define a named type (“why do i have to define a struct when all i want is a dictionary key pair?”)

with the exception of the big three Hashable, Comparable, and Codable, my guess is if you care enough to want your tuple to conform to something, then (2) doesn’t really apply, so maybe ExpressibleByTupleLiteral (1, 2, 3) combined with magic EHC+Codable would solve the problem.

6 Likes