In this recipe, we are going to explore three useful extension functions from the standard library—let, also, and apply. They work great together with lambda expressions and help to write clean and safe code. We are going to practice their usage while applying them to implement a sequence of data-processing operations.
Discovering basic scoping functions – let, also, apply
Getting ready
Let's assume we can fetch the date using the following function:
fun getPlayers(): List<Player>?
Here, the Player class is defined like this:
data class Player(val name: String, val bestScore: Int)
We would like to perform the following sequence of operations to the getPlayers() function result:
- Print the original...