Search code examples
functionidempotentpure-function

Are idempotent functions the same as pure functions?


I read Wikipedia's explanation of idempotence. I know it means a function's output is determined by its input. But I remember that I heard a very similar concept: pure function. I Google them but can't find their difference...

Are they equivalent?


Solution

  • An idempotent function can cause idempotent side-effects.

    A pure function cannot.

    For example, a function which sets the text of a textbox is idempotent (because multiple calls will display the same text), but not pure.
    Similarly, deleting a record by GUID (not by count) is idempotent, because the row stays deleted after subsequent calls. (additional calls do nothing)