Good point, but let me disagree on that. If it was true, then, for example, LabelledGeneric
would have never been created in Shapeless (why?). Named tuples are not just about removing some friction – this feature introduces a possibility to create a type that can represent a nested data structure including field names and moreover can be shared among all data types with the same set of fields. For example, with named tuples we can do something like this:
type MyData = (
aaa: (
bbb: Seq[(ccc: Int, ddd: String)],
eee: (
fff: Seq[Double]
)
),
ggg: Boolean
)
Note that it is a type, not a class. Case classes, on the other hand, would require to have a separate class instance at each level of nesting. Moreover, we can use named tuples to run transformations between different case classes. (I’m not sure though if has been supported in Scala already, but if not, I believe it is a matter of time). We cannot use regular case classes for that.
But also as consequence of the above, yes, named tuples can reduce some friction too, which is a nice perk, but not the selling point, I think.
Collection literals, on the other hand, do not introduce anything new apart of the ability to shortcut Seq(1, 2, 3)
to [1, 2, 3]
.
PS. It’s just appeared to me that even with named tuples we have to use Seq[Whatever]
if we want to define a type for a collection of items. Therefore, if we really want to make collection literals blended into Scala syntax nicely, then we may need to get something like this:
type MyData = (
aaa: (
bbb: [(ccc: Int, ddd: String)],
eee: (
fff: [Double]
)
),
ggg: Boolean
Otherwise, it would be yet another point of confusion:
(123, "abc")
has type(Int, String)
(name = "John", age = 33)
has type(name: String, age: Int)
Seq(1, 2, 3)
has typeSeq[Int]
[1, 2, 3]
sorry, but onlySeq[Int]
too
From this point of view, the entire collection literal feature does not seem belonging in Scala language in general, if you will.