This syntax is already in the language if you a wi...
# language-proposals
This syntax is already in the language if you a willing to prefix your "literal" with a keyword like
arr["a", "b", "c"]
(can be implemented via
voddan: oh, really pleased to see there are now even more operators
[i, ... i_n]
didn't exist before
@elect When did it not exist?
operator get
is there from very early versions. This is how
were always implemented
there was only one argument get and set
­čĺę 1
I guess
Get and set operators not changed
This approach has a hidden performance problem: 2 allocations instead of 1, one for vararg array, and another for the resulting collection. In fact, you can already do "collection builders", which do not suffer from additional allocations and are in fact more flexible. Syntax might be a bit more verbose compared to what you'd expect from collection literals / collection comprehensions.
@dmitry.petrov can't we reuse the vararg array unto the list?
Yes, sure. You'll need a (Mutable)List implementation that will expose the corresponding constructor. Also possible (but probably somewhat less effective) for sets and maps. Yet, I'd prefer builder-based approach myself.