realm-kotlin
realm-kotlin copied to clipboard
Add support for RealmSet
Follow the pattern of managed/unmanaged used for lists by using delegates.
An oversimplified API would look like this:
interface RealmSet<E> : MutableSet<E>
internal class UnmanagedRealmSet<E>: RealmSet<E>,
MutableSet<E> by mutableSetOf()
internal class ManagedRealmSet<E>(
val nativePointer: NativePointer
): AbstractMutableSet<E>(), RealmSet<E> {
// TODO
}
/**
* Instantiates an **unmanaged** [RealmSet].
*/
fun <E> realmSetOf(vararg elements: E): RealmSet<E> = UnmanagedRealmSet()
/**
* Instantiates an **unmanaged** [RealmSet] containing all the entries of this set.
*/
fun <E> Set<E>.toRealmSet(): RealmSet<E> = TODO()
Observations:
- the C-API has defined the methods for sets but is still missing their implementations.
- the majority of methods from the
MutableSet
interface are already provided byAbstractMutableSet
though they might not be optimised, e.g.addAll
iterates over all values in the provided collection and then callsadd
. - It doesn't seem necessary to rely on
Mixed
as the transport solution since the C-API acceptsrealm_value_t
structs, just asRealmList
does.