A function is said to be idempotent when it can be called multiple times without changing the result.
Idempotence is a property of certain function in mathematics or computer science. It states that the function can be applied multiple times without changing the result from the result of applying the function a single time.
Examples from mathematics
Multiplying some value by 1, or by 0; these should give the same result no matter how many times they are applied. I.e.:
(x * 1) == (1 * (1 * x)) == (1 * (1 * (1 * x))) == ...
abs(x):
abs(-3) == 3
, butabs(3) == 3
too. Similarlyabs(abs(-3)) == abs(abs(abs(-3))) ...
Examples from computer sience
- HTTP-context: A GET-operation or a DELETE-operation; each of these should effect the same results each time. A counter-example could be a post-operation, which may result in a different outcome / state each time it is called (calling it multiple times may result in duplicate date being stored, for instance).
- Setting a (boolean) flag; the resulting state should be the same whether you set it once or many times.