September 2023
Intermediate to advanced
470 pages
11h 12m
English
The exercises in this chapter will focus on functors and errors.
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.
We have seen how to create a constant functor, so let’s define some further methods on it. The method combine will allow us to combine two Holders passing a function with two parameters.
The exercise consists of implementing the combine method with this signature:
| | fun combine(other: Holder<T>, f: (T, T) -> T): Holder<T> = |
| | TODO() |
…so that we can write code like this:
| | val h = Holder( ... |
Read now
Unlock full access