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

commonMain.state.kt Maven / Gradle / Ivy

Go to download

Provides fully-fledged multishot delimitied continuations in Kotlin with Coroutines

The newest version!
public data class StateValue(public var value: T)

public typealias State = Reader>

public suspend fun  State.set(value: T) {
  ask().value = value
}

public suspend fun  State.get() = ask().value

public suspend inline fun  State.modify(f: (T) -> T) = set(f(get()))

public suspend fun  runState(value: T, body: suspend State.() -> R): R = with(State()) {
  pushState(value) { body() }
}

public suspend fun  State.pushState(value: T, body: suspend () -> R): R =
  pushReader(StateValue(value), { copy() }, body)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy