Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does the Scala library only defines tuples up to Tuple22?

Tags:

I'm curious if anyone knows why the Scala library stops at 22 with its tuple type Tuple22?
Does the mysterious number 22 have a special hidden meaning?
Is this an internal joke of some kind?

like image 415
Ori Avatar asked Jun 05 '11 06:06

Ori


People also ask

What is a benefit of using tuples in Scala?

In Scala, a tuple is a value that contains a fixed number of elements, each with its own type. Tuples are immutable. Tuples are especially handy for returning multiple values from a method.

Can we have variables of different types inside a tuple Scala?

Thankfully, Scala already has a built-in tuple type, which is an immutable data structure that we can use for holding up to 22 elements with different types.

Are tuples mutable Scala?

A tuple is immutable, unlike an array in scala which is mutable. An example of a tuple storing an integer, a string, and boolean value. Type of tuple is defined by, the number of the element it contains and datatype of those elements.


2 Answers

This question is not new, see http://scala-programming-language.1934581.n4.nabble.com/Why-tuples-only-to-22-td1945314.html or why FunctionN(0-22) ProductN(1-22) TupleN(1-22)?

AFAIK there is no "technical" explanation for it, they simply had to stop somewhere.

like image 86
Landei Avatar answered Sep 20 '22 01:09

Landei


I believe it has to do with difficulties in implementing a static type system while having variadic (arbitrary-argument) functions. I believe apply can be written in Scala (though not in Haskell, at least not elegantly).

like image 44
ninjagecko Avatar answered Sep 19 '22 01:09

ninjagecko