mirror of
https://github.com/alrayyes/wiki.git
synced 2024-11-22 03:26:22 +00:00
816 B
816 B
date | id | title |
---|---|---|
2020-11-26 | 48609306-f2e9-4d01-b774-7d3ec34703aa | idempotent |
Origin
Idem is latin for 'same'.
Definition
An operation or function, that when called multiple times will always produce the same result.
Examples
Idempotent
console.log(1 * 1 * 1 * 1)
const set = new Set()
set.add('blaat')
set.add('blaat')
set.add('blaat')
console.log(set) // { 'blaat' }
Practial examples
- Get, Put & Delete endpoints on a REST api
- Payment operations. Reposting the same form should not result in multiple charges to the customer.
Non idempotent
console.log(2 * 2 * 2 * 2)
const arr = []
arr.push('blaat')
arr.push('blaat')
arr.push('blaat')
console.log(arr) // [ 'blaat', 'blaat', 'blaat' ]