Programming in Kotlin - Part 22: More Functions | Ray Wenderlich

More Functions: Learn some more advanced features of functions, such as overloading, and functions as variables.


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/4736-programming-in-kotlin/lessons/22

I donโ€™t understand the need to add a function to a variable and then call that variable, when you can just call the function?

what is the advantage?

If you are talking about the โ€œfunctionโ€ variable, one of the advantages to having a variable point to another function is that you can change the method it is pointing to. For example, we could start by pointing it to the add function, pass that variable to a function, then change function to point to another function like subtract and have it do some more work.