Closed vsimko closed 3 years ago
What is pure function?
Well, a pure function is such a function which does not have any side effects and for any input it always returns the same output. For example, a mathematical function such as f(x) = x^2
is pure. However, function f(x) = sample(1:10, x)
isn't pure because it returns different random values for the same input. Also a function f(x) = print(x)
isn't pure because it causes a side effect (printing to console).
Pure functions behave nicely, they can be easily tested and reason about.
https://github.com/taiyun/corrplot/blob/430e501c71f09d8100358d8053b52bfaec004996/R/corrplot.R#L1047-L1067
If these functions are drawing something, this means they cannot be pure because they have a side effect.