A tuple is a finite ordered list of elements. It is presented as a parentheses-braced, comma-delimited list. In Swift, you can use them as stand-alone heterogenous lists of values or pass them as arguments to functions and closures.
A tuple is pronounced “tupple” (TUH-ple), not “two-pull”. It’s a shortcut pulled from “double, triple, quintuple, sextuple, octuple”, etc. Yes, please note that “quadruple” doesn’t fit with the others and is not used as a basis for speaking the word. Rules about long and short “u”s that apply to other English words are also not relevant to this case.
In Swift, a tuple is analogous to an anonymous struct. Its members are indexed numerically (.0
, .1
, .2
, etc). You can also use labels to access members by name:
let point = (x: 5.0, y: 2.3) print(point.1) // 2.3 print(point.y) // 2.3
Swift 3.0 and later no longer supports splatting, so you cannot decouple a tuple from a function call. You can read more about this in SE-0029, which disallowed the ability. Before the change, you could call a function either with its direct arguments or by passing a tuple:
func foo(a : Int, b : Int) {} foo(a: 42, b : 17) // still allowed let x = (a: 1, b: 2) foo(x) // no longer allowed in Swift 3+
The continued work on SE-0110 is still resolving on how tuples and closures interact.
The word “arity” describes the number of members in a tuple. (It also describes the number of arguments or operands accepted by a function, method, or closure.) The examples above use an arity of 2. You can call this a “2-arity tuple” or the shortcut “2-ary tuple”. Some shorten that further to a “2-tuple”. All are acceptable.
Some fun facts to finish with:
- A figurative tuple with an arbitrary arity is an “n-arity” or “n-ary” or “n-tuple”.
- A tuple with a variable number of arguments is variadic.
8 Comments
Americanese pronunciation statements of “fact” are about as relevant as the America’s fascination with the term World Series.
Or…
https://twitter.com/gvanrossum/status/86144775731941376?lang=en
quintuple, sextuple, septuple etc all end in -oople as far as I am concerned. Hence toople
I like “toople” because it sounds funnier, and also because then a 3-tuple is a threeple.
Sorry, I like “toople”. All the dictionaries I’ve checked also use “quintoople”, “sextoople”, etc.
Webster third has quintuple pronounced like kwin-t(y)üpel. The (y)ü being like numerous sounding like ee-yoo so my best guess for consistency is tyoople. So not two-ple or toople and not tuh-ple.
In original English quintuple, sextuple and, indeed, quadruple are all “toople” so I, for one, will be sticking with that pronunciation. I always go with the old-fashioned Oxford English Dictionary over any newcomer.
If it’s supposed to be pronounced “tupple” then why isn’t spelled “tupple”? ????