Metakit / @doeixd/metakit/pairs

idempotent

function · packages/metakit/src/transitionCommutes.ts:126

function idempotent<State, Input, Emit, Supplied>(
  transition: Transition<State, Input, Emit, Supplied>,
  options?: ReaderOptions,
): Verdict.Verdict<never>

Whether transition run twice in a row, with the same input and supplied values, leaves the state once leaves, decided from its footprint and the ways its writes name, never by running it:

  1. An opaque term (ordinary code, or a term that may read anything) is Unknown.
  2. A transition that emits records emits them twice: Unknown.
  3. A read of a path it writes (in its guard or a written value) may give another answer the second time, or refuse it: Unknown.
  4. Each write's way must list idempotent in writeProperties, and meet its condition; an add or an append does not list it.
  5. Otherwise True. (A transition never writes a path and one under it, so no write undoes another.)

A combine meets rule 4 only where its operation's idempotent and associative claims apply under options.rewritePolicy, as in commutes.

It never answers False. A copy delivered later, after other writes, is a question of commutes as well; this answers the copy that follows at once.