funtion type notation kotlin code example
Example 1: kotlin higher order functions
fun main() {
higherOrderSequence(5, ::square)
}
fun higherOrderSequence(num: Int, myFunc: (Int) -> Int) {
// A function declared as an argument must specify input and return type
for (x in 1..num) {
print("${myFunc(x)} ")
}
println()
}
fun square(num: Int):Int {
return num * num
}
Example 2: make function kotlin
fun main() {
println("This is a function")
}