If I pass a callable function to a higher order function (::function) I have access to the complete name and signature of the function in the higher order function, whereas if I use a lambda({i->function}) I just got the arguments.
It is possible to get the function name using a lambda? I found confusing that calling the same function with different syntax I’ve got different results. Besides I really need to know which function I’m running actually in the high order function. I’m I right if I conclude that I should use callable functions to satisfy that need. ?
Thank you
suspend fun testafun(i:Int){
delay(100)
logger.info {"($i)"}
}
fun testAsync( size:Int, fun: suspend(i:Int) -> Unit ):String{
return "testAsync for ${fun}"
}
fun main() {
val size = 3
val msg = """
testAsync ----> ${testAsync(size,::testafun)}
testAsync ----> ${testAsync(size) { i->testafun(i)} }
""".trimIndent()
println(msg)
}
result prints the following:
testAsync ----> testAsync for fun testafun(kotlin.Int): kotlin.Unit
testAsync ----> testAsync for (kotlin.Int) → kotlin.Unit