Skip to content

Make ordered & non-ordered set/map implementations distinguishable #128

@bubenheimer

Description

@bubenheimer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions