13 Sharing mutable states with actors
- Understanding the actor model
- Using asynchronous messaging
- Building an actor framework
- Putting actors to work
- Optimizing actor performance
In the previous chapters, you learned many techniques to help you write safer programs. Most of these techniques come from functional programming. One of these techniques consist in using immutable data to avoid state mutations. Programs without mutable states are safer, more reliable, and easier to design and scale.
You learned how mutable states can be handled in a functional way by passing the state along as an argument to functions. You saw several examples of this technique. You learned to generate streams of data by passing the state of a generator together with each new value. (If you don’t remember this, review exercise 9.29 where you implemented the unfold function by passing along each generated value together with the new state of the generator.) In chapter 12, you also learned how to pass the console as a parameter to send output to the screen and receive input from the keyboard. These techniques can be widely applied to many domains. But this is often understood to mean that functional programming techniques help to safely share mutable state. This is completely wrong.