Idempotence: What is it, and why should you care?

Just do it once

Steven Curtis
3 min readAug 25, 2021
YouTube Link

I’ve already mentioned Idempotence in my HTTP Methods article, but I think it is worth going into the detail here and understanding exactly what this rather long word means.

Idempotence: A changeable definition

I’ve previously defined Idempotent as “An operation that produces the same results if executed multiple times”

In imperative programming, an idempotent function will produce the same state with one or many calls

In functional programming, a pure function is idempotent so you might be better off looking at the pure function article to get a grip of avoiding side-effects in the way that we describe here as “Idempotent”

A basic example

Sets in Swift have the property that the same item cannot appear twice within the set. This means that the following:

leaves us with a set — containing just the Integer 1. Once we have run set.insert(1) we are guaranteeing that…

--

--

No responses yet