scala / docs.scala-lang

The Scala Documentation website
http://docs.scala-lang.org
561 stars 1.03k forks source link

Scala 3 book - collections - tuple apply access? #2031

Open Sciss opened 3 years ago

Sciss commented 3 years ago

https://github.com/scala/docs.scala-lang/blob/main/_overviews/scala3-book/taste-collections.md

I just intuitively tried if tuple apply works with static indices, and it does, which is very cool. I don't know if that should be the preferred way to access them? I.e. instead of

case class Person(name: String)

val t = (11, "eleven", Person("Eleven"))

t._1   // 11
t._2   // "eleven"
t._3   // Person("Eleven")

would it be better to write

t(0)   // 11
t(1)   // "eleven"
t(2)   // Person("Eleven")

?

bishabosha commented 3 years ago

Yes I think this would be a nice addition