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?
+8
A:
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
2010-09-01 12:47:44
thank you for your help"
2010-09-01 13:23:04
There'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
2010-09-01 13:50:55
I guess stopping at 23 would have given the occasion to conspiracy theories...
Landei
2010-09-01 15:01:58
You are off by one: that is why *they* invented `Function0` and `Unit` - so there are actually 23 of each.
Moritz
2010-09-01 15:50:23