The api has FunctionN(0-22) ProductN(1-22) TupleN(1-22) the question is: 1.why the number is end of 22? why not 21 or 23? 2.why Function is start with 0 ? but Product and Tuple are not?
Asked
Active
Viewed 1,465 times
1 Answers
12
It does not make sense to have a Product
or a Tuple
that contains no elements. These would be equivalent to Unit
.
Function0
exists because a function does not necessarily take arguments (e.g. in the case of by-name arguments).
In the case of Tuple22
and Function22
I cannot tell why the Scala team chose 22 as a maximum but it definitely is awkward to have tuples with that many members or functions that take more than 22 arguments.
It could be though that there is a restriction on how many arguments to a method the JVM can handle.

Moritz
- 14,144
- 2
- 56
- 55
-
6There's no technical reason to stop at 22, actually. It's automatically generated, but it had to stop at _some_ number. People have used the creating scripts to generate bigger tuples and functions. – Daniel C. Sobral Sep 01 '10 at 13:50
-
1You are off by one: that is why *they* invented `Function0` and `Unit` - so there are actually 23 of each. – Moritz Sep 01 '10 at 15:50
-
@Landei probably inspired by Jim Carrey's movie? – asgs Jun 20 '17 at 18:26