September 2023
Intermediate to advanced
470 pages
11h 12m
English
The exercises in this chapter will focus on different types of monads.
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 saw how a TaggedValue functor can’t be a monad unless the tag type has a monoid instance. Now, we consider something similar, replacing the tag enum to a list of strings that we want to use as an operation log.
For this exercise, you have to implement the Logger monad and add a test to prove it honors the monad’s laws:
| | data class Logger<T>(val value: T, val log: List<String>) { |
| | ... |
Read now
Unlock full access