Home > Articles > Data > SQL Server

  • Print
  • + Share This
Like this article? We recommend

Tuple Limitations

Swift tuples include significant limitations. You cannot programmatically create tuples ("Build me a tuple of length n"). Tuples cannot have mutable length, and there are no variadic tuples (although you can add variadic elements within tuples).

What's more, there's no such thing as a 1-tuple. It's a "nope-le," or, more accurately, a scalar. In Swift, foo and (foo) are identical. In theory, Swift has a labeled 1-tuple; for example, (a:42), but this also currently acts as a simple scalar:

let x = (a:42)
x // 42
x == 42 // true
x == (42) // true
x == (a:42) // true
// x.a  // error 'Int' does not have a member named 'a'

Swift reflection lets you count the number of fields within a type. The counts returned for these examples are instructive:

var a = (1, 6, 4)
var b = (2,3)
var c = (2)
var d = ()

reflect(a).count // 3
reflect(b).count // 2
reflect(c).count // 0, scalar, not a tuple, Int 2
reflect(d).count // 0, Void
  • + Share This
  • 🔖 Save To Your Account