Answers for "kotlin higher order functions"

1

kotlin closures

They are called lambdas ;)
Posted by: Guest on October-03-2020
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
}
Posted by: Guest on November-03-2020

Code answers related to "kotlin higher order functions"

Browse Popular Code Answers by Language