Summary

In this chapter, we discussed the effects defined in the standard library. First, an Option which represents a case where it might be impossible for the function to return the result. Then the Try which extends the optionality with the possibility to return an error description in the failure case. Next was Either which further extends the concept of Try by allowing it to provide an arbitrary type as a description of an unsuccessful path. Finally, the Future which stays a bit aside in this list and represents the notion of long and possibly executed in separate context computations

We noticed that these effects have different constructors tailored to the situations that require the creation of the respective instances. In accordance, they offer slightly different ways to access values that are stored inside the container.

We paid attention to the fact that having effects as a first-class concept allows us to define methods not only in terms of contained values but also in terms of the effect itself, which often leads to more expressive code.

Most importantly, we realized that many methods such as filtercollectmapflatMap, and so, are on identical from the user's perspective and induce identical, higher level implementations for different kinds of effects. We demonstrated this by implementing four uniform examples for catching a fish in a few steps, encoded in terms of different effects.

Later in this book, we will identify the underlying concepts that lead to these kinds of similarities.

We'll also approach the topic of combining different kinds of effects, which we left out of scope for now.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.163.229