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

commonMain.resetDsl.kt Maven / Gradle / Ivy

Go to download

Provides fully-fledged multishot delimitied continuations in Kotlin with Coroutines

The newest version!
public fun interface Cont {
  public suspend fun resumeWith(value: Result): R
  public suspend operator fun invoke(value: T): R = resumeWith(Result.success(value))
  public suspend fun resumeWithException(exception: Throwable): R = resumeWith(Result.failure(exception))
}

@ResetDsl
public suspend fun  Prompt.reset(body: suspend () -> R): R = pushPrompt(body = body)

@ResetDsl
public suspend fun  newReset(body: suspend Prompt.() -> R): R = with(Prompt()) { reset { body() } }

public suspend fun  topReset(body: suspend Prompt.() -> R): R = runCC { newReset(body) }

@ResetDsl
public suspend inline fun  Prompt.shift(crossinline block: suspend (Cont) -> R): T =
  takeSubCont(deleteDelimiter = false) { sk -> block { sk.pushSubContWith(it, isDelimiting = true) } }

@ResetDsl
public suspend inline fun  Prompt.shiftOnce(crossinline block: suspend (Cont) -> R): T =
  takeSubContOnce(deleteDelimiter = false) { sk -> block { sk.pushSubContWith(it, isDelimiting = true) } }

@ResetDsl
public suspend inline fun  Prompt.control(crossinline block: suspend (Cont) -> R): T =
  takeSubCont(deleteDelimiter = false) { sk -> block { sk.pushSubContWith(it) } }

@ResetDsl
public suspend inline fun  Prompt.shift0(crossinline block: suspend (Cont) -> R): T =
  takeSubCont { sk -> block { sk.pushSubContWith(it, isDelimiting = true) } }

@ResetDsl
public suspend inline fun  Prompt.control0(crossinline block: suspend (Cont) -> R): T =
  takeSubCont { sk -> block { sk.pushSubContWith(it) } }

@ResetDsl
public fun  Prompt.abortWith(value: Result): Nothing = abortWith(deleteDelimiter = false, value)

@ResetDsl
public fun  Prompt.abortWith0(value: Result): Nothing = abortWith(deleteDelimiter = true, value)

@ResetDsl
public fun  Prompt.abort(value: R): Nothing = abortWith(Result.success(value))

@ResetDsl
public fun  Prompt.abort0(value: R): Nothing = abortWith0(Result.success(value))

@ResetDsl
public fun  Prompt.abortS(value: suspend () -> R): Nothing = abortS(deleteDelimiter = false, value)

@ResetDsl
public fun  Prompt.abortS0(value: suspend () -> R): Nothing = abortS(deleteDelimiter = true, value)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy