15 Stateful programs and stateful computations
This chapter covers
- What makes a program stateful?
- Writing stateful programs without mutating state
- Generating random structures
- Composing stateful computations
Since chapter 1, I’ve been preaching against state mutation as a side effect that should be avoided at almost any cost, and you’ve seen several examples of refactoring programs to avoid state mutation. In this chapter, you’ll see how the functional approach works when keeping state is a requirement rather than an implementation detail of your program.
But what’s a stateful program exactly? It’s a program whose behavior differs, depending on past inputs or events.1 By analogy, if somebody says, “Good morning,” you’ll probably mindlessly ...
Get Functional Programming in C#, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.