Quick run through on what pure and impure functions are.
A function is considered pure if:
a) It always returns the same value when given the same arguments
b) It does not modify anything (arguments, state, database, I/O, ..)
A function is considered impure if it is not pure (!), typically because:
a) it makes use of an external or random value. (It stops being entirely contained and predictable)
b) It performs an external operation, in other words it causes side effects
The reason why Pure Function are great:
Yep, I know, it’s part of the definition, but using a function and knowing exactly what it does feels so good.
Pure functions can be reused easily as they do not hold any form of state.
Since the result will always be the same, it becomes easy to cache results.
Last but not least, pure functions are easy and a pleasure to test with automated tests.