it: The Implicit Parameter
Use the implicit 'it' parameter in single-parameter lambdas.
The Implicit it
When a lambda has exactly one parameter, you can omit declaring it and reference it as it. Saves typing for short pipelines.
it in forEach
The classic example: forEach passes each element as it.
fun main() {
listOf(1, 2, 3).forEach { println(it) }
}All lessons in this course
- What Is a Lambda? Syntax and Types
- Passing Lambdas to Functions
- it: The Implicit Parameter
- filter, map, and find on Collections