I want my extension function to have a couple of receivers. For example, I want function handle
to be able to call methods of both CoroutineScope
and Iterable
instances:
fun handle() {
// I want to call CoroutineScope.launch() and Iterable.map() functions here
map {
launch { /* ... */ }
}
}
I thought this might work:
fun <T> (Iterable<T>, CoroutineScope).handle() {}
But it gives me an error:
Function declaration must have a name
I know that I can create the function with parameters, but
Is it possible to have multiple receivers for a single function and how to do that without parameters?
build.gradle.kts
file is:tasks.withType<KotlinNativeCompile>().configureEach { kotlinOptions { freeCompilerArgs += "-Xcontext-receivers" } }
. That's how you add free compiler args when using Kotlin/Native. I didn't find this information anywhere. – Master