I understand that in the final version of the cont...
# arrow
c
I understand that in the final version of the context parameters this will not be an error, right?
s
It's already working fine in 2025.1 with 2.1.0 for me with
Copy code
kotlin {
    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:
Copy code
// 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")
}
c
Copy code
interface 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...
s
Yes, I am also kind-of missing it a bit. Context receivers worked this way.
Someone needs to write a KSP plugin
@GenerateContextParams
😅
🤔 2
c
I've been using context receivers for at least a year, and I haven't encountered any problems, aside from the typical "this@something." I guess I haven't considered any other issues that might have arisen. I'll miss context receivers... haha.
p
I had thought a compiler plugin applied to an interface expected to be used contextually would automatically create context-parameter bridge methods (i.e. for
Raise<E>
automatically generate
context(r: Raise<E>) fun <E, A> ensureNotNull(value: A?, raise: () -> E) = r.ensureNotNull(value, raise)