Make ordered & non-ordered set/map implementations distinguishable
bubenheimer opened this issue · comments
Uli Bubenheimer commented
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.
Abduqodiri Qurbonzoda commented
Ralated #106