Gabriel Rajadurai thank you for your response.

We can return a function from a higher order function. Please check the below syntax.

fun outerFunction(): () -> Unit {    var iAmAVariable = 10    return fun() {
print("I am inside the returning function")
}
}

we can also return an object from the returning function.

fun outerFunction(): () -> Int {    var iAmAVariable = 10    return fun() : Int {
iAmAVariable += 10
return iAmAVariable
}
}

Or we can even call some other function from a returning function also.

fun outerFunction(): () -> Unit {    var iAmAVariable = 10    return fun() {
someOtherFunction()
}
}
fun someOtherFunction() {
print("I am another function")
}

Hope this helps. :)

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