Kotlin provides a set of idioms that allows us to drastically reduce the amount of boilerplate code. Boilerplate refers to sections of code that have to be included in many places with little or no alteration. In this section, we will learn some of the most used idioms.
Using Kotlin idioms
Inferred types
We may have a function written that returns a value, such as:
fun lower(name : String) : String {
val lower : String = name.toLowerCase()
return "$name in lower case is: $lower"
}
Here, we are explicitly indicating the type of the result of the function and the internal variable that we use inside.
In Kotlin, we could infer the type of the variable:
fun lower(name : String): String {
val lower = name.toLowerCase...