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?
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.
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.
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.
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With