All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.entity.optional.delegate.OptionalIntDelegate.kt Maven / Gradle / Ivy

The newest version!
package dev.kord.common.entity.optional.delegate

import dev.kord.common.entity.optional.OptionalInt
import dev.kord.common.entity.optional.optionalInt
import dev.kord.common.entity.optional.value
import kotlin.js.JsName
import kotlin.jvm.JvmName
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KMutableProperty0
import kotlin.reflect.KProperty

@JsName("intDelegate")
public fun KMutableProperty0.delegate(): ReadWriteProperty = object : ReadWriteProperty {

    override fun getValue(thisRef: Any?, property: KProperty<*>): Int? {
        return [email protected]().value
    }

    override fun setValue(thisRef: Any?, property: KProperty<*>, value: Int?) {
        val optional = if (value == null) OptionalInt.Missing
        else OptionalInt.Value(value)
        [email protected](optional)
    }

}

@JvmName("provideNullableDelegate")
public fun KMutableProperty0.delegate(): ReadWriteProperty = object : ReadWriteProperty {

    override fun getValue(thisRef: Any?, property: KProperty<*>): Int? {
        return [email protected]().value
    }

    override fun setValue(thisRef: Any?, property: KProperty<*>, value: Int?) {
        [email protected](value?.optionalInt())
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy