kotlinx.collections.immutable icon indicating copy to clipboard operation
kotlinx.collections.immutable copied to clipboard

Make ordered & non-ordered set/map implementations distinguishable

Open bubenheimer opened this issue 2 years ago • 1 comments

I am adding some API on top of the provided persistent types, but I am running into trouble with maps/sets, because ordered and non-ordered implementations are indistinguishable. My specific use case is making the types @Stable for Jetpack Compose, but I believe this issue applies generally to extending the existing APIs.

For example:

@Stable
interface StablePersistentList<out E> : PersistentList<E>

val <E> PersistentList<E>.stable: StablePersistentList<E>
    get() = if (isEmpty()) EmptyStableList
    else object : StablePersistentList<E>, PersistentList<E> by this {}

private val EmptyStableList: StablePersistentList<Nothing> =
    object : StablePersistentList<Nothing>, PersistentList<Nothing> by persistentListOf() {}

This works well, but in the case of sets & maps I cannot similarly defer to an EmptyStableSet/EmptyStableMap, because there are 2 distinct implementations (ordered/non-ordered), and there is no way to determine which one is passed in.

bubenheimer avatar May 27 '22 14:05 bubenheimer

Ralated https://github.com/Kotlin/kotlinx.collections.immutable/issues/106

qurbonzoda avatar Jun 29 '22 10:06 qurbonzoda