Wouldn’t it be nice if `.toList()`, `.map()`, `.fi...
# stdlib
m
Wouldn’t it be nice if
.toList()
,
.map()
,
.filter()
,
listOf()
, etc. use some immutable
List
subclass internally, so that subsequent calls to
.toList()
don’t have to create another copy? 🙂 Would be great for defensive copy patterns, since you don’t know whether the list you get is immutable or not.
m
.toXxx()
is copying by definition
m
No it isn’t. Where does it say that? Documentation only states “Returns a List containing all elements.“: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/to-list.html
m
hmm, but we have
.asXxx()
for returning view on
this
collection
m
.asXX()
could be immutable depending on whether the underlying collection is immutable, hence
.toList()
could even here just return
this
in some cases 😄