Higher-order functions: Difference between revisions

m
Line 1,520:
}</lang>
 
Another example showing the syntactic sugar available to Kotlin developers which allows them to put the lambda expression out of the parenthesis whenever the function is the last argument of the higher order function. Notice the usage of the inline modifier, which inlines the bytecode of the argument function on the callsite, reducing the object creation overhead (an optimization for pre Java 8 JVM environments, like Android) (translation from Scala example):
<lang scala>
inline fun higherOrderFunction(x: Int, y: Int, function: (Int, Int) -> Int) = function(x, y)
 
fun main(args: Array<String>) {
Anonymous user