What is Idempotence? Given the same inputs with the same output. It is similar to pure function but it is a little bit different.

Not Idempotence function

function notIdempotence(n){
    return Math.random(n);

the result is continually changed.
  • This is not idempotence.

Idempotence function but not pure

function idempotence_but_not_pure(n){
    return console.log(n);

This function is idempotence. However, this function is not pure function because console.log().

# Another thing that can be idempotent for example is deleting a user from a database. Idempotence, you see a lot in APIs, like HTTP get requests.

Leave a Reply

Your email address will not be published.