Behaving Properly – Pure Functions
In Chapter 3, Starting Out with Functions, we considered functions as the critical elements in functional programming (FP), went into detail about arrow functions, and introduced some concepts, such as injection, callbacks, polyfilling, and stubbing. In this chapter, we’ll have the opportunity to revisit or apply some of those ideas.
In this chapter, we will do the following:
- Consider the notion of purity and why we should care about pure functions—and impure functions as well!
- Examine the concept of referential transparency
- Recognize the problems implied by side effects
- Show some advantages of pure functions
- Describe the main reasons behind impure functions
- Discover ways to minimize the number of impure functions
- Focus on ways of testing both pure and impure functions