Skip to content

Commit

Permalink
refactor(#9): update serialization of NotEmptySet
Browse files Browse the repository at this point in the history
  • Loading branch information
LVMVRQUXL committed Dec 28, 2022
1 parent 9ead764 commit f37c598
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/commonMain/kotlin/kotools/types/collection/NotEmptySet.kt
Expand Up @@ -64,13 +64,17 @@ public fun <E> notEmptySetOf(head: E, vararg tail: E): NotEmptySet<E> =

internal class NotEmptySetSerializer<E>(elementSerializer: KSerializer<E>) :
KSerializer<NotEmptySet<E>> {
private val delegate: KSerializer<Set<E>> = SetSerializer(elementSerializer)
private val delegate: KSerializer<Set<E>> by lazy {
SetSerializer(elementSerializer)
}

@ExperimentalSerializationApi
override val descriptor: SerialDescriptor = SerialDescriptor(
"${Package.collection}.NotEmptySet",
delegate.descriptor
)
override val descriptor: SerialDescriptor by lazy {
SerialDescriptor(
"${Package.collection}.NotEmptySet",
delegate.descriptor
)
}

override fun serialize(encoder: Encoder, value: NotEmptySet<E>): Unit =
encoder.encodeSerializableValue(delegate, value.asSet)
Expand Down

0 comments on commit f37c598

Please sign in to comment.