I am following this guide to begin learning functional programming w/ Javascript: https://medium.com/@cscalfani/so-you-want-to-be-a-functional-programmer-part-1-1f15e387e536#.iynj38h83
It defines a Pure function as:
- Operate only on input parameters
- Useful Pure functions take at least one parametre
- Useful Pure functions must return something
- Pure functions cannot change external variables/No side effects
- Pure functions will always produce the same output given the same input
The following function violates the contract:
function notPure(data) {
let ts = new Date();
return md5(data + ts);
}
But the following would be Pure:
function pureFunction(data, ts) {
return md5(data + ts);
}
Assuming I understand correctly, what is the point? I'm young to this part of the field. I don't yet understand how this is useful. Does the inclusion of the time stamp inside the function make the function stateful and break purity?
What is the advantage to forcing these values to be created elsewhere and passed into a pure function as a parameter?