October 2021
Intermediate to advanced
500 pages
16h 23m
English
Take another look at your Narrator.kt file:
val narrationModifier = { message: String ->
val numExclamationPoints = 3
message.uppercase() + "!".repeat(numExclamationPoints)
}
fun narrate(
message: String
) {
println(narrationModifier(message))
}
Eagle-eyed readers may have noticed a disappointing reality: Everything that you have done so far could have been accomplished without using lambdas. This same logic could have been expressed with a single non-anonymous function, like this:
fun narrate(
message: String
) {
val numExclamationPoints = 3
println(message.uppercase() + "!".repeat(numExclamationPoints))
}
Fear not: The work you have done so far has not been in vain. Lambdas shine when you need to change ...
Read now
Unlock full access