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

commonMain.arrow.optics.State.kt Maven / Gradle / Ivy

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