Chapter 2. Why function purity matters

This chapter covers

  • What makes a function pure or impure
  • Why purity matters in concurrent scenarios
  • How purity relates to testability
  • Reducing the impure footprint of your code

The initial name for this chapter was “The irresistible appeal of purity.” But if it was so irresistible, we’d have more functional programmers, right? Functional programmers, you see, are suckers for pure functions—functions with no side effects. As you’ll see in this chapter, pure functions have some very desirable properties.

Unfortunately, the fascination with pure functions and what you can do with them is partly why FP as a discipline has become disconnected from the industry. As you’ll soon realize, there’s very little ...

Get Functional Programming in C# 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.