Reputation: 617
I'm learning functional programming. I have a very specific question.
Technically can a class method be considered a pure function?
Let's say we have an add method: add(a, b) { return a + b }
. Is the add method a pure function or should it be declared outside of the class to be considered as a pure function?
Upvotes: 0
Views: 953
Reputation: 665456
Should it be declared outside of the class to be considered as a pure function?
No, it doesn't matter. Purity (or: referential transparency) is a property of what the function (the code inside it) does, not where it is stored.
Upvotes: 4