O'Reilly logo

Functional Programming in C#: How to write better C# code by Enrico Buonanno

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 12. 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 there’s a requirement for the program to be stateful.

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 greet them in return. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required