DEV Community

Discussion on: Functional programming basics part 1: Pure function

Collapse
 
qm3ster profile image
Mihail Malo

Any useful function returning void is definitely impure.
Even if it doesn't reference anything besides its parameters, it's still bound to mutate or otherwise bother the parameters.
A pure function:

  1. has no effect on the world except returning something.
  2. the return value depends only on the parameters.

One of the consequences of 2. is that when given the same parameters, it should always produce the same return value.

This is a useful dipping stick that demonstrates that functions that depend on eg time or randomness aren't pure.