I don’t remember why we didn’t want to use the spread operator for this.
val x: Seq[Int] = (1, 3, 5, 2, 7)*
creates a tuple literal, then, if there’s an appropriate typeclass, spreads it into a constructor for Seq[Int]
.
As a nice perk, there’s no reason this shouldn’t work for conversion between sequence types too.
val x: DataEntry = (name = "John", age = 42, color = Web.PaleVioletRed)*
packs into a case class with names as defined. (Need to decide whether unnamed tuples come along for free or whether you have to add an extra typeclass.)
And, I guess,
val sushi: Map[String, Int] = ("eel" -> 2, "salmon" -> 5)*
can work too, using the same scheme as []
.
It’s a rather less dramatic syntactic change, and it’s more explicit that magic is happening because you say the magic everywhere.
Because we already have the idea of the spread operator, it’s a less dramatic change than mixing type notation and instance notation. (Again, unless we view [1, 5, 2]
as a type literal from which we can summon an instance.)