Attach a non-enumerable .match method to a TaskResult so callers can
use the fluent form result.match({ completed: ..., failed: ... }).
Non-enumerable so JSON.stringify(result), {...result}, and
Object.keys(result) are unaffected — the method only surfaces through
direct property access and autocomplete. Note: because the method is
non-enumerable, shallow clones like const r = {...result} or
structuredClone(result) do NOT carry the method over. Use the free
function match(clone, handlers) on clones, or call attachMatch(clone)
to re-decorate.
Idempotent: if .match is already present, the result is returned
unchanged. Safe to call on results that have already been decorated
(e.g., a result forwarded through multiple client layers).
Attach a non-enumerable
.matchmethod to aTaskResultso callers can use the fluent formresult.match({ completed: ..., failed: ... }).Non-enumerable so
JSON.stringify(result),{...result}, andObject.keys(result)are unaffected — the method only surfaces through direct property access and autocomplete. Note: because the method is non-enumerable, shallow clones likeconst r = {...result}orstructuredClone(result)do NOT carry the method over. Use the free functionmatch(clone, handlers)on clones, or callattachMatch(clone)to re-decorate.Idempotent: if
.matchis already present, the result is returned unchanged. Safe to call on results that have already been decorated (e.g., a result forwarded through multiple client layers).