Suneet Agrawal
1 min readOct 13, 2018

--

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. :)

--

--