June 2018
Intermediate to advanced
316 pages
6h 34m
English
To solve the problem described in the previous section, we can just create a new method like this:
fun predicate(student: Student) = ageMoreThan20(student) && firstNameStartsWithE(student) && theLengthOfSecondNameMoreThan5(student)students.filter(::predicate)
Or you can create the method like this:
students.filter(fun(student: Student) = ageMoreThan20(student) && firstNameStartsWithE(student) && theLengthOfSecondNameMoreThan5(student))
By using function composition, we can reach a more elegant solution like this:
students .filter(::ageMoreThan20 and ::firstNameStartsWithE and ::theLengthOfSecondNameMoreThan5)
Function composition is the combining of two or more functions to create a new function. It's a powerful approach ...
Read now
Unlock full access