Pure functions behave in the same way as mathematical functions and provide diverse benefits. A function may be considered to be pure if it satisfies two conditions:
- Given the same arguments, the function always calculates and returns the same result, no matter how many times it's invoked, or in which conditions you call it. This result value cannot depend on any outside information or state, which could change during the program execution, and cause it to return a different value. Nor can the function result depend on I/O results, random numbers, or some other external variable, not directly controllable, value.
- When calculating its result, the function doesn't cause any observable side effect, including output to I/O devices, mutation of objects, change to program state outside of the function, and so on.
If you want, you can simply say...