Functions are first-class citizens of the Kotlin programming language. This means functions can be stored as variables and passed as arguments to other functions. Kotlin has been designed to make functions easy to write and flexible to use. This section will introduce you to functions in Kotlin and help you explore what it means to have first-class support for functions.
Hello functions – first-class support for functions
Writing a basic function
Let's jump in and look at a basic function written in Kotlin:
// Main.kt
fun helloFunctions(greeting: String) {
println("$greeting Kotlin Functions")
}
This snippet demonstrates a fully functional, and quite simple, function written in Kotlin. There are several...