Pure Functions
The purest of functions can be considered black boxes, meaning that what happens inside the function is not really of any interest to the programmer. They are only interested in what is put into the box, and what comes out of it as a result—that's because there will always be a result of a pure function.
The pure function takes arguments and produces a result based on these arguments. The pure function will never change the state of the outside world or rely on it. Everything that is required by the function should be available inside it, or as an input to it.
Exercise 1: Writing Pure Functions
A grocery store has a system for managing their stock; however, the company that built their software has gone bankrupt and has lost all the source code for their system. This is a system that only allows customers to buy one thing at a time. Because their customers want to buy two things at a time, never more or less, they have asked you to implement a function...