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

commonMain.stackState.kt Maven / Gradle / Ivy

Go to download

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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy