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

commonMain.fcontrol.kt Maven / Gradle / Ivy

Go to download

Provides fully-fledged multishot delimitied continuations in Kotlin with Coroutines

The newest version!
import kotlin.jvm.JvmInline

@JvmInline
public value class Fcontrol private constructor(private val reader: Reader T>) {
  public constructor() : this(Reader())

  @ResetDsl
  public suspend fun fcontrol(error: Error): T = reader.ask()(error)

  @ResetDsl
  public suspend fun  resetFcontrol(
    handler: suspend (Error, SubCont) -> R, body: suspend () -> R
  ): R {
    val prompt = Prompt()
    return reader.pushReader({ prompt.takeSubCont(false) { k -> handler(it, k) } }) {
      prompt.pushPrompt(body)
    }
  }

  @ResetDsl
  public suspend fun  resetFcontrol0(
    handler: suspend (Error, SubCont) -> R, body: suspend () -> R
  ): R {
    val prompt = Prompt()
    return reader.pushReader({
      prompt.takeSubCont { k ->
        reader.deleteBinding()
        handler(it, k)
      }
    }) {
      prompt.pushPrompt(body)
    }
  }
}

@ResetDsl
public suspend fun  newResetFcontrol(
  handler: suspend Fcontrol.(Error, SubCont) -> R, body: suspend Fcontrol.() -> R
): R = with(Fcontrol()) {
  resetFcontrol({ e, k -> handler(e, k) }) { body() }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy