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:
- An opaque term (ordinary code, or a term that may read anything) is
Unknown. - A transition that emits records emits them twice:
Unknown. - 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. - Each write's way must list
idempotentinwriteProperties, and meet its condition; anaddor anappenddoes not list it. - 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.