IntermediateLambdas
Extension Function
Add functions to existing types.
kotlin
fun String.greet(): String {
return "Hello, $this"
}
fun main() {
println("Kotlin".greet())
}Output
Hello, Kotlin
Explanation
Extension functions add new functionality to existing types without modifying them. this refers to the receiver object (the String).