Writing Testable Code with Pure Functions
When you read about functional programming, quite often, what is meant is “pure” functional programming. As we touched on in the first chapter, this is not a strict requirement of functional programming or functional languages. If you decide to pick up a functional programming language, the chances are pretty high that you’ll pick up a language such as Haskell or Elm. If so, you would have chosen two purely functional languages and might have coupled your understanding of pure functional with functional. On the other hand, if you had picked up a language such as Lisp, Clojure, or Erlang, you would have picked a functional language that is impure yet still functional.
In this chapter, we will address the following topics:
- What exactly is purity?
- Why should purity matter?
- How do we create pure functions?
- Learning how unit testing is impacted by writing pure functions