Chapter 14. Sharing mutable state with actors

 

This chapter covers

  • Understanding the actor model
  • Using asynchronous messaging
  • Building an actor framework
  • Putting actors to work
  • Optimizing actor performance

In working through this book, you first learned that functional programming often deals with immutable data, which results in programs that are safer, more reliable, and easier to design and scale. Then you learned how mutable state can be handled in a functional way by passing the state along as an argument to functions. You saw several examples of this technique:

  • Passing the generator while generating random numbers allowed for increased testability.
  • Passing the console as a parameter allowed you to send functional output to the screen and receive input from the keyboard.

This technique can be widely applied to many domains. In imperative programming, parsing a file is generally handled by continuously mutating the state of a component that represents the result of the parsing. To make this process compatible with functional programming, you just have to pass the state as an additional argument to all parsing functions. Logging can be done the same way, as well as monitoring performance: instead of writing to a log file in each function, you can make the function receive the log file as an argument, and return the augmented file as part of the result.

14.1. The actor model

14.2. Building the actor framework

14.3. Putting actors to work

14.4. Summary