
Kotlin Design Patterns and Best Practices
By :

We already covered some of the functional capabilities of Kotlin in the chapters dedicated to design patterns. The Strategy and Command design patterns are only two examples that rely heavily on the ability to accept functions as arguments, return functions, store functions as values, or put functions inside of collections. In this section, we'll cover some other aspects of functional programming in Kotlin, such as function purity and currying.
As we discussed previously, in Kotlin, it's possible for a function to return another function. Let's look at the following simple function to understand this syntax in depth:
fun generateMultiply(): (Int) -> Int { return fun(x: Int): Int { return x * 2 } }
Here, our generateMultiply
function returns another function that doesn't have a name. Functions without...