NotEmptySet

@Serializable(with = NotEmptySetSerializer::class)
@Since(version = KotoolsTypesVersion.V4_0_0)
value class NotEmptySet<out E> : NotEmptyCollection<E>

Represents a set that has at least one element of type E.

You can use the notEmptySetOf or the toNotEmptySet functions for creating an instance of this type.


Serialization and deserialization

The serialization and deserialization processes of this type behave like for the Set type.

Here's an example of Kotlin code that encodes and decodes this type using the JavaScript Object Notation (JSON) format from kotlinx.serialization:

val string: NotEmptySet<Int> = notEmptySetOf(1, 2, 3)
val encoded: String = Json.encodeToString(string)
assertEquals(expected = "[1,2,3]", actual = encoded)
val decoded: NotEmptySet<Int> = Json.decodeFromString(encoded)
assertEquals(expected = string, actual = decoded)

Types

Link copied to clipboard
object Companion

Contains static declarations for the NotEmptySet type.

Properties

Link copied to clipboard
open override val head: E

The first element of this collection.

Link copied to clipboard

The size of this collection.

Link copied to clipboard
@Since(version = KotoolsTypesVersion.V4_1_0)
val NotEmptyCollection<*>?.sizeOrZero: PositiveInt

Returns the size of this collection, or returns ZeroInt if this collection is null.

Link copied to clipboard
open override val tail: NotEmptySet<E>?

All elements of this collection except the first one.

Functions

Link copied to clipboard
fun toSet(): Set<E>

Returns all elements of this set as a Set of type E.

Link copied to clipboard
open override fun toString(): String

Returns the string representation of this collection.