Appendix 1. Appendix - The Algebra of Library Design
You might have noticed that all of the reactive abstractions that you have encountered in this book have a few things in common. For one, they work as container-like abstractions, which can be described as follows:
- Futures encapsulate a computation that eventually yields a single value
- Observables encapsulate computations that can yield multiple values over time, in the shape of a stream
- Channels encapsulate the values pushed to them, and they can have the values being popped from the channel, working as a concurrent queue through which concurrent processes can communicate
Once we have a container, we can operate on it in a number of ways, which are very similar across the different abstractions and frameworks. We can filter
the values contained in them; transform them by using map
; combine abstractions of the same type by using bind
, flatMap
, or selectMany
; execute multiple computations in parallel; aggregate the results by using sequence
; and much more.
As such, even though the abstractions and their underlying functionalities are fundamentally different, it still feels as if they belong to some type of higher-level abstractions.
In this appendix, we will explore what these higher-level abstractions are, the relationships between them, and how we can take advantage of them in our projects.