Hello there. I started working with high-order functions and everything works fine if I use a high-order function by calling the given parameter function action
.
Example:
fun execute( action: (Int) -> Unit ) { val myInt = 5 action(myInt)
}
execute { it -> println(it) // Output: 5 }
But now I wanted to call a method with a function as parameter, which again passes this function to another function like this:
fun execute( action: (Int) -> Unit ) { ... secondFunction(action) // this does not work
}
fun secondFunction( action: (Int) -> Unit) { val myInt = 5 action(myInt) } execute { it -> println(it) // Output: 5 }
Is this even possible and if it is, how does this work?
Thanks for your help!
submitted by /u/cyb3rko
[link] [comments]