August 2017
Intermediate to advanced
440 pages
10h
English
In some cases, we define a lambda expression that does not use all its parameters. When we leave them named, they might be distracting to a programmer who is reading the lambda expression and trying to understand its purpose. Let's look at the function that filters every second element. The second parameter is the element value, and it is unused in this example:
list.filterIndexed { index, value -> index % 2 == 0 }
To prevent a misunderstanding, there are some conventions used, such as ignoring the parameter names:
list.filterIndexed { index, ignored -> index % 2 == 0 }
Because these conventions were unclear and problematic, Kotlin introduced underscore notation, which is used as a replacement for the names ...
Read now
Unlock full access