Skip to content
Justice Tech School

Lambdas and Higher Order Functions

A lambda is { params -> body }. it is the single parameter name.

Example
val sq = { x: Int -> x * x }
println(sq(5))
println(listOf(1, 2, 3).map { it * 2 })
fun twice(f: (Int) -> Int, x: Int) = f(f(x))
println(twice({ it + 3 }, 1))

Exercise

Single parameter name.

list.map {  * 2 }

Quiz Test

What is it?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.