Higher Order Function Kotlin

typealias HigherFun = (String,String) -> Unit
typealias Lmbd= () -> Unit

var lambda = { println("Tell me about yourself....?") }

fun callingHigherFuncLmbd( lmbd: Lmbd ) {
lmbd() //Invoke Lambda Expression
//or by invoke method
//lmbd.invoke()
}

fun callingHigherFunWithParam(listener: HigherFun){
listener("Good Evening ","Jack") //Invoke higher oreder Fun
//or by invoke method
// listener.invoke("","")
}

fun callingHigherFunWithParams(name :String,listener: HigherFun){
listener("I'm ",name+" with basic programming skills.") //Invoke higher oreder Fun
//or by invoke method
// listener.invoke("","")
}


fun main(args: Array<String>) {

val name ="Jones"

callingHigherFuncLmbd(lambda) // sepertate fun for calling lmbd higher order functiom

callingHigherFunWithParam { var1: String, var2: String ->
println(var1+var2) // Definition of Higher Order Fun with param
}

// sepertate fun for calling higher order functiom with param

callingHigherFunWithParams(name,{ var1: String, var2: String ->
println(var1+var2)
})
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store