OptionalDouble

Represents a value that encapsulate the optional and value state of an Int in the Discord API. Specifically:

  • Missing - an Int field that was not present in the serialized entity.

  • Value - an Int field that was assigned a non-null value in the serialized entity.

Note that there is no nullable variant present. Use Int? or OptionalDouble? for this case instead.

The base class is (de)serializable with kotlinx.serialization.

Note that kotlinx.serialization does not call serializers for values that are not present in the serialized format. Optional fields should have a default value of OptionalDouble.Missing:

@Serializable
public data class CreateSoundboardSoundRequest(
val name: String,
val sound: String,
val volume: OptionalDouble? = OptionalDouble.Missing,
@SerialName("emoji_id")
val emojiId: OptionalSnowflake? = OptionalSnowflake.Missing,
@SerialName("emoji_name")
val emojiName: Optional<String?> = Optional.Missing(),
)

Inheritors

Types

Link copied to clipboard

Represents an Int field that was not present in the serialized entity.

Link copied to clipboard
class Value(val value: Double) : OptionalDouble

Represents a field that was assigned a non-null value in the serialized entity. Equality and hashcode is implemented through its value.

Properties

Link copied to clipboard
Link copied to clipboard

returns null if this is null, calls OptionalDouble.asNullable otherwise.

Link copied to clipboard
Link copied to clipboard

returns null if this is null or OptionalDouble.Missing, calls OptionalDouble.Value.value otherwise.

Functions

Link copied to clipboard

returns the value of the optional or throws a IllegalStateException if the optional doesn't contain a value or is null.

Link copied to clipboard
inline fun OptionalDouble.map(mapper: (Double) -> Double): OptionalDouble
Link copied to clipboard
fun orElse(default: Double): Double

returns default if the optional is Missing, or Value.value if is Value.

Link copied to clipboard
fun OptionalDouble?.orElse(default: Int): Int

returns default if this is null, calls OptionalDouble.asNullable otherwise.