commonMain.arrow.optics.State.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of arrow-optics-compose Show documentation
Show all versions of arrow-optics-compose Show documentation
Functional companion to Kotlin's Standard Library
The newest version!
@file:JvmName("ComposeStateKt")
package arrow.optics
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
import kotlin.jvm.JvmName
/**
* Exposes the value of [this] through the optic.
*/
public fun State.optic(g: Lens): State = object : State {
override val value: A
get() = g.get([email protected])
}
/**
* Exposes the value of [this] through the optic.
* Any change made to [value] is reflected in the original [MutableState].
*/
public fun MutableState.optic(lens: Lens): MutableState = object : MutableState {
override var value: A
get() = lens.get([email protected])
set(newValue) {
[email protected] = lens.set([email protected], newValue)
}
override fun component1(): A = value
override fun component2(): (A) -> Unit = { value = it }
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy