Is there somewhere that details the differences be...
# getting-started
Is there somewhere that details the differences between a top-level function variable, and a top-level function, and what considerations there are in choosing one over the other?
Copy code
val topLevelFunctionVariable: (String) -> Int = { it.length }
fun topLevelFunction(value: String): Int = value.length
The real difference in this case, you can use into some Class as a client callback function for example.
there is also the slight difference that - at least when running on jvm - your function variable will store the lambda wrapped in an object. This object is not needed for the top level function. Because you can use method references, you can even use the top level function as a parameter for higher order functions. In general I would suggest sticking to functions instead of variables holding lambdas. They may be the way to go in JS/TS, but in my experience are very uncommon in Kotlin.
@Tobias Berger that is true, however for top-level declarations, that additional object hardly makes any difference.