Scala: function / method application and tuples

I came across some pretty interesting behavior in Scala.

scala> def foo(t: (Int, Int, Int)): Int = t._1 
foo: (t: (Int, Int, Int))Int

scala> foo(1,2,3)
res23: Int = 1

scala> foo((1,2,3))
res24: Int = 1

This also works the other way around:

scala> Some(1,2,3,4,5)     
res31: Some[(Int, Int, Int, Int, Int)] = Some((1,2,3,4,5))

Although this sugar is extremely healthy, I have not found any documentation on this. Therefore, my question is mainly: where is it described in the Scala Language Specification, and what other consequences have this, if any.

Regards, raichoo

+5
source share
1 answer

Automatic repetition is known. I filed an error in accordance with the language specification, which was silent on this issue.

Here is the corresponding part of the compiler source code.

+2
source

All Articles