Kotlin Function Types With Examples

In Kotlin, functions are treated as values. Just like your integer values or strings - you can assign functions to a variable. Kotlin is considered as First-Class Function Language i.e. functions are treated as values. You can store them in a variable, pass them as parameters and return a function from a function. Function Type Since functions are just like other values, there is a type that is associated with the functions. That type is known as Function Type. Let's look at some examples - 1. (Double, Double) -> Double This is how we define a function type. If a variable has this data type then it can take any function which takes 2 doubles as input parameters and returns the output as Double. Function signature contains 2 things - What is the type of input parameters and what is the return type of the function. So when you define a function type you need to mention these 2 things. Before the arrow ( ->) you define the types of input parameters i.e. Double, Double in th