Just out of curiosity: Was it ever considered to r...
# stdlib
a
Just out of curiosity: Was it ever considered to remove the infix function
to
from the stdlib and make it some encapsulated function of a map builder scope so that we can write:
Copy code
val squared = mapOf { // this refers to some MapBuilderScope<K,V> with builder inference
    1 to 1 // `to` is only visible in the `MapBuilderScope`
    2 to 4
    3 to 9
}
m
Well, it should not be necessary (and possible) to remove the current `to`function, the scope's should take precedence.
a
Why is it not possible in your opinion?
m
It is too commonly used, not only to build maps.
1
r
See https://youtrack.jetbrains.com/issue/KT-43871 for proper collection literals
a
I belong to the fraction of people who don't like collection literals. On the other hand I don't like that
to
pollutes the global namespace and extends the
Any?
type. Having a limited scope of
to
inside a builder context would eliminate that issue imho.
j
This would require changes to many utility functions, such as the
associate
family. Also it would prevent things like
map { a to b }.toMap()
(but more complicated) in cases where
associate
cannot be directly used for some reason, and force people to use the
Pair()
constructor manually. I'm not sure it's objectively better tbh
a
Good point @Joffrey