commonMain.state.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kontinuity Show documentation
Show all versions of kontinuity Show documentation
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)