September 2023
Intermediate to advanced
470 pages
11h 12m
English
The exercises in this chapter will focus on nullable types and partial application.
Here is your friendly reminder that nobody can learn functional programming by just reading code, and the best way to learn is by practicing. You can refer to the exercises folder in the book code repository for the starting point and some hints.
For this exercise, let’s create a general higher-order function to return null if some predicate is true. Try to implement this function:
| | fun <T> T.discardUnless(predicate: T.() -> Boolean): T? = |
…in a way that allows these tests to pass:
| | val itemInProgress = ToDoItem("doing something", |
| | status= ToDoStatus.InProgress) |
| | val itemBlocked = ToDoItem("must do something" ... |
Read now
Unlock full access