Lambdas and Higher Order Functions
A lambda is a function written in braces. Functions can take or return other functions. The last lambda argument can go outside the parentheses.
Example
val double = { x: Int -> x * 2 }
fun apply(n: Int, f: (Int) -> Int) = f(n)
println(apply(5, double))
println(apply(5) { it + 100 })Exercise
Lambda parameter arrow.
{ x: Int x * 2 }
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.