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
source
share