carbaj0
04/30/2025, 5:54 AMsimon.vergauwen
04/30/2025, 6:11 AMkotlin {
compilerOptions.freeCompilerArgs.add("-Xcontext-parameters")
}
But you'd need to new module Ale build as well, https://github.com/arrow-kt/arrow/pull/3606
So you can do this:
// Defined in Arrow-kt Raise module
context(raise: Raise<Error>)
fun <Error> raise(error: Error): Nothing =
raise.raise(error)
// Another example.
context(scope: CoroutineScope)
fun launch(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
block: suspend CoroutineScope.() -> Unit
): Job = scope.launch(context, start, block)
context(_: Raise<String>, _: CoroutineScope)
suspend fun example() {
launch { println("Launch without explicit receiver") }
raise("poop")
}
carbaj0
04/30/2025, 6:51 AMinterface Logger {
fun debug(message: String)
fun info(message: String)
fun warn(message: String)
fun error(message: String, throwable: Throwable? = null)
fun log(message: String)
}
context(logger : Logger)
fun logDebug(message: String) {
logger.debug(message)
}
context(_: Logger)
fun logInfo(message: String) {
logDebug(message)
}
ok, if i want to access to a specific function inside of an Inteface, i have to create first his own function.
i have been thinking that context params behaves like an Extension Funtion...simon.vergauwen
04/30/2025, 7:00 AMsimon.vergauwen
04/30/2025, 7:01 AM@GenerateContextParams
😅carbaj0
04/30/2025, 9:36 AMphldavies
04/30/2025, 11:30 AMRaise<E>
automatically generate context(r: Raise<E>) fun <E, A> ensureNotNull(value: A?, raise: () -> E) = r.ensureNotNull(value, raise)