July 2018
Intermediate to advanced
242 pages
8h 6m
English
In order to get familiar with function composition, let's study the following example. Let's say we have the following functions defined:
fun length(word: String) = word.lengthfun isEven(x:Int): Boolean = x.rem(2) == 0
The first one is responsible for returning the length of a given string. The second one checks whether a given integer is even. In order to define a new function based on those two functions, we can make nested function calls:
fun isCharCountEven(word: String): Boolean = isEven(length(word))
This works fine, however, it would be useful if we were able to operate on the function references instead. In order to make it more concise we'd like to be able to declare the isCharCountEven() function using the following ...
Read now
Unlock full access