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

后端 未结 4 1146
予麋鹿
予麋鹿 2020-12-20 11:19

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 s

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-20 12:16

    Limit 22 is one of the dropped features of dotty (Scala 3) which now allows tuples of arbitrary arity:

    The limits of 22 for... the maximal number of fields in tuple types have been dropped... tuples beyond Tuple22 are erased to a new trait scala.TupleXXL.

    For example,

    object Main {
      def main(args: Array[String]): Unit = {
        val tuple: Tuple = ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25")
        println(tuple.getClass)
        println(tuple.size)
      }
    }
    

    outputs

    class scala.TupleXXL
    25
    

    For further examples see Add tests for the current tuple API #7633

提交回复
热议问题