July 2018
Intermediate to advanced
400 pages
12h 14m
English
Like any other type, the function type is also a valid return type, meaning you can define a function that returns a function.
In SimVillage, define a configureGreetingFunction function that configures the arguments for the lambda held by the greetingFunction variable and generates and then returns the lambda, ready for use:
Listing 5.13 Adding the configureGreetingFunction function (SimVillage.kt)
fun main(args: Array<String>) {
runSimulation("Guyal", ::printContructionCost) { playerName, numBuildings ->
val currentYear = 2018
println("Adding $numBuildings houses")
"Welcome to SimVillage, $playerName! (copyright $currentYear)"
}
runSimulation()
}
inline fun runSimulation(playerName: String,
costPrinter: ...Read now
Unlock full access