Florian G
Florian G

Reputation: 617

Can a method be a pure function?

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

Answers (1)

Bergi
Bergi

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

Related Questions