docs.scala-lang icon indicating copy to clipboard operation
docs.scala-lang copied to clipboard

Scala 3 book - collections - tuple apply access?

Open Sciss opened this issue 4 years ago • 1 comments

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")

?

Sciss avatar May 18 '21 21:05 Sciss

Yes I think this would be a nice addition

bishabosha avatar May 19 '21 11:05 bishabosha