Has it ever been possible calling an extension function this way?
Copy code
fun String.myFunction(param: Int) { }
// ...
"receiver".myFunction(5)
// but instead...
myFunction("receiver", 5)
I'm positive I was able to do that from Kotlin.
e
ephemient
02/21/2023, 9:59 PM
no. but if it were a value
Copy code
myFunction: String.(param: Int) -> Unit
instead (such as a property or function parameter), then
"receiver".myFunction(5)
and
myFunction("receiver", 5)
would be equivalent
đ€Ż 1
r
Ruckus
02/21/2023, 10:00 PM
Not on a function call directly, but you can on lambdas or function references:
Copy code
fun String.myFunction(param: Int) {}
// ...
fun main() {
val myFunction = String::myFunction
"receiver".myFunction(5)
// but instead...
myFunction("receiver", 5)
}