commonMain.entity.optional.delegate.OptionalBooleanDelegate.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-common-jvm Show documentation
Show all versions of kord-common-jvm Show documentation
Idiomatic Kotlin Wrapper for The Discord API
The newest version!
package dev.kord.common.entity.optional.delegate
import dev.kord.common.entity.optional.OptionalBoolean
import dev.kord.common.entity.optional.optional
import dev.kord.common.entity.optional.value
import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty
public fun KMutableProperty0.delegate(): ReadWriteProperty =
object : ReadWriteProperty {
override fun getValue(thisRef: Any?, property: KProperty<*>): Boolean? {
return [email protected]().value
}
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean?) {
val optional = if (value == null) OptionalBoolean.Missing
else OptionalBoolean.Value(value)
[email protected](optional)
}
}
@JvmName("provideNullableDelegate")
public fun KMutableProperty0.delegate(): ReadWriteProperty =
object : ReadWriteProperty {
override fun getValue(thisRef: T, property: KProperty<*>): Boolean? {
return [email protected]().value
}
override fun setValue(thisRef: T, property: KProperty<*>, value: Boolean?) {
[email protected](value?.optional())
}
}