<https://kotlinlang.slack.com/archives/C0B8Q383C/p...
# stdlib
i
https://kotlinlang.slack.com/archives/C0B8Q383C/p1493038673085550?thread_ts=1492976413.401231&amp;cid=C0B8Q383C By the way, have you tried this one? https://github.com/Kotlin/kotlinx.collections.immutable It might be not as good in terms of performance, since right now we're more interested in its API convenience feedback.
m
Yes, I tried to replace my
List
usage with this, but the API is not convinient. I even told you a while ago what issues I had 🙂
I don't think reusing
kotlin.List
will work. It needs to be a separate
List
interface like this one: https://github.com/vavr-io/vavr/blob/master/vavr/src/main/java/io/vavr/collection/List.java
i
I've interested to hear why it won't work. Do you have specific considerations against?
m
Well, maybe it "might" work, but you need to provide implementations for all functions that are there in the stdlib for given supertype, including extension functions.
I was trying to replace list with
ImmutableList
and then was hitting things like
take
or
drop
not defined on this interface.
But the code there was compiling, just returning ordinary
List
.
So I'd rather not put
List
as superinterface for
ImmutableList
and then users would clearly see what's possible and what's not.
i
That's a valid concern, I've stumbled upon it too, see the issue https://github.com/Kotlin/kotlinx.collections.immutable/issues/10 Though currently it doesn't look entirely impassable, I believe we can find some solution if stdlib operators could get know something about immutable collections.
m
For me
take
on
ImmutableList
simply needs to return
ImmutableList
. There is no other option to connect it all with
data class
copy and friends.
I don't want casts or
toImmutableList()
after every such call.
Gotta go. Always happy to give me more feedback on immutable stuff.
I have a lot of code that does
this.copy(someList = this.someList + elem)
or
val (six, rest) = this.someList.splitAt(6); this.copy(someList = six)
, so all functions on
ImmutableList
should return the same type.