Is there no overhead calling `toMutableList()` aga...
# getting-started
t
Is there no overhead calling
toMutableList()
again after mapping?
m
Depends on the actual type of list. If the list is already mutable, then there's no overhead. If it's not, then it copies all elements to a mutable list.
t
Okay I see
s
Collection<T>.toMutableList()
always copies
If you want to end up with something else than a
List
then I suggest you use
mapTo()
m
Oh, it does? That's weird.
k
Because you can use a
MutableList
as a
List
it would be pretty weird if it only sometimes copied.
m
Yeah, nevermind. The not-copying optimization would only make sense for immutable lists.
t
Hmm.. why I wanted to avoid it earlier. Thanks.