-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename fcontrol in preparation for a proper effect handler interface
- Loading branch information
Showing
3 changed files
with
24 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,32 @@ | ||
import kotlin.jvm.JvmInline | ||
|
||
@JvmInline | ||
public value class Handle<Error, T> internal constructor(private val reader: Reader<suspend (Error) -> T>) { | ||
public value class Fcontrol<Error, T> internal constructor(private val reader: Reader<suspend (Error) -> T>) { | ||
public constructor() : this(Reader()) | ||
|
||
@ResetDsl | ||
public suspend fun fcontrol(error: Error): T = reader.ask()(error) | ||
|
||
@ResetDsl | ||
public suspend fun <R> resetWithHandler( | ||
handler: suspend (Error, Cont<T, R>) -> R, body: suspend () -> R | ||
public suspend fun <R> resetFcontrol( | ||
handler: suspend (Error, SubCont<T, R>) -> R, body: suspend () -> R | ||
): R { | ||
val prompt = Prompt<R>() | ||
return prompt.pushPrompt(extraContext = reader.context { prompt.control { k -> handler(it, k) } }, body = body) | ||
return prompt.pushPrompt(extraContext = reader.context { prompt.takeSubCont(false) { k -> handler(it, k) } }, body = body) | ||
} | ||
|
||
@ResetDsl | ||
public suspend fun <R> resetWithHandler0( | ||
handler: suspend (Error, Cont<T, R>) -> R, body: suspend () -> R | ||
public suspend fun <R> resetFcontrol0( | ||
handler: suspend (Error, SubCont<T, R>) -> R, body: suspend () -> R | ||
): R { | ||
val prompt = Prompt<R>() | ||
return prompt.pushPrompt(extraContext = reader.context { prompt.control0 { k -> handler(it, k) } }, body = body) | ||
return prompt.pushPrompt(extraContext = reader.context { prompt.takeSubCont { k -> handler(it, k) } }, body = body) | ||
} | ||
} | ||
|
||
@ResetDsl | ||
public suspend fun <Error, T, R> newResetWithHandler( | ||
handler: suspend Handle<Error, T>.(Error, Cont<T, R>) -> R, body: suspend Handle<Error, T>.() -> R | ||
): R = with(Handle<Error, T>()) { | ||
resetWithHandler({ e, k -> handler(e, k) }) { body() } | ||
public suspend fun <Error, T, R> newResetFcontrol( | ||
handler: suspend Fcontrol<Error, T>.(Error, SubCont<T, R>) -> R, body: suspend Fcontrol<Error, T>.() -> R | ||
): R = with(Fcontrol<Error, T>()) { | ||
resetFcontrol({ e, k -> handler(e, k) }) { body() } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters