concept lambda in category kotlin

appears as: lambda, lambdas
The Joy of Kotlin

This is an excerpt from Manning's book The Joy of Kotlin.

All parameters of the lambda passed as the argument of the forAll function are generated by the standard generators provided by Kotlintest. This might not be what you need. For integers, the default generator is provided by the Gen.int() function. The previous test is then equivalent to

When the lambda is the last argument of a function, it can be put outside of the parentheses:

fun triple(list: List<Int>): List<Int> = list.map { a -> a * 3 }

fun product(list: List<Int>): Int = list.fold(1) { a, b -> a * b }

In the map example, the lambda is not only the last argument, but the only one, so the parentheses can be removed. As you may have noticed in the second example, the arguments of the lambda don’t need to be put between parentheses. In fact, you can’t put parentheses around them because it would change the meaning. This would not compile: