Thinking in Terms of Functors
At this point, you’ve seen a few different uses for functors. It’s important to understand them very well, because the next chapter will build heavily upon them. Can we abstract some rules about designing with functors and what they can give us? To try to answer these questions, we can consider that functors are useful in these situations:
-
We have some data that’s “bound” to something else—for example, a number in a list of numbers, or a result and its failure.
-
We want to operate on the data, ignoring its context.
Functors allow us to keep the two different concerns separated. In other words, they add some kind of effect on a pure function. This is what distinguishes functional effects from nonfunctional side effects. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access