The way I see it by now, the core of this proposal is one thing: making it easier/terser to refer to the type expected where the expression is located. Let’s say we use @
as a placeholder for that type. If a List
is expected, then @(1,2,3)
will be List(1,2,3)
. If a Person
is expected, @("Matthias", @.of(???, 7, 11))
will be Person("Matthias", LocalDate.of(???, 7, 11))
(assuming that the second field of Person
has type LocalDate
).
This syntax doesn’t know or care whether it’s being used to build a case class
, a collection, or even something else like a LocalDate
(which is a Java class and hence neither of the two). This is very simple to explain and teach, and I would even say that it’s probably easy to implement as well, because a lot of the machinery is already in place. The types of Lambda parameters are deduced from the type expected in that position, so the Scala compiler already has some notion of that expected type. And the rules for how the whole “placeholder” thing works are also already specified, because we already have a type of expression that uses a placeholder, namely the abbreviated lambda syntax with _
as a placeholder.
To make the syntax even cleaner, we could say that @foo
is equivalent to @.foo
, e. g. @of(???, 7, 11)
for LocalDate
.
At the risk of tooting my own horn here: to me, this feels just right. It’s simple in every way I can think of, it’s quite flexible and general, and it has the potential to massively cut down on boilerplate. What’s not to like?