commonMain.stackState.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kontinuity-jvm Show documentation
Show all versions of kontinuity-jvm Show documentation
Provides fully-fledged multishot delimitied continuations in Kotlin with Coroutines
The newest version!
public typealias StackState = State>
public suspend operator fun StackState.plusAssign(value: T) = modify { it + value }
public suspend fun StackState.getLast() = ask().value.last()
public suspend inline fun StackState.modifyLast(f: (T) -> T) = plusAssign(f(getLast()))
public suspend fun runStackState(value: T, body: suspend StackState.() -> R): R =
runState(listOf(value), body)
public suspend fun StackState.pushStackState(value: T, body: suspend () -> R): R =
pushState(listOf(value), body)
public suspend fun StackState.pushStackStateWithCurrent(value: T, body: suspend () -> R): R {
val current = askOrNull()?.value ?: emptyList()
return pushState(current + value, body)
}