Description
Tuple is a very important core class of the Scala 3 standard library. But its organization was a jumble of different styles, with major omissions in functionality and a lack of consistency.
I made an effort in #19172 to improve Tuple.scala
and in #19174 to align NamedTuple.scala
and Tuple.scala
. The work is not finished yet, and it would be great if someone could continue it. In particular:
- Make sure that every type we define has a corresponding method implementing that type, or if that does not make sense, explain in the doc comment of the type why there is no method.
- Make sure doc comments are consistent and helpful.
- Make sure we have tests for all operations.
- Have we missed important operations?
- Make sure Tuple and NamedTuple are aligned.
One area where NamedTuple
and Tuple
are not aligned is that there is no concept of "non-empty tuple" for named tuples. I believe adding that to Tuple
was a big mistake. If you look at the definition of Tuple
you'll find seemingly arbitrary and non-sensical definitions that sometimes use Tuple and sometimes use EmptyTuple. For instance
type Head[X <: NonEmptyTuple]
type Last[X <: Tuple]
Why is Head
only defined for NonEmptyTuple
whereas Last
is defined for Tuple
? That makes no sense!
The problem comes up because "being non empty" is a structural property of a tuple and we want to express it with a nominal type. That's usually a bad idea since nominal types are just not expressive enough. So the end result is that we shoot ourselves in the foot, and that for zero gains in safety. In fact, Last
above is just as safe as Head
. When applied to the empty tuple, neither of them reduces to a type.