unthrown icon indicating copy to clipboard operation
unthrown copied to clipboard

`matchTags` has no async overload (asymmetry with async `match`)

Open btravers opened this issue 5 months ago • 1 comments

Summary

matchTags only accepts a synchronous Result. match already has an async form (on AsyncResult, resolving to Promise<R>), but matchTags has no equivalent — so on an AsyncResult you must await first.

Why it matters

It's a small asymmetry, but it breaks the otherwise-uniform "every combinator has an async counterpart" mental model:

// works
await asyncResult.match({ ok, err, defect });

// no async form — must await first
matchTags(await asyncResult, handlers);

Proposal

Add an async overload (or an AsyncResult.matchTags method) mirroring the async match, resolving to Promise<R>. Low priority — purely an ergonomics/symmetry fix.

btravers avatar Jun 26 '26 14:06 btravers

Already implemented and tested. matchTags carries an async overload that resolves to Promise<R>:

export function matchTags<T, E extends { _tag: string }, R>(
  result: AsyncResult<T, E>,
  handlers: TagHandlers<T, E, R>,
): Promise<R>;

So await matchTags(asyncResult, handlers) works without awaiting first. Covered by packages/core/src/tagged.spec.ts → "folds an AsyncResult to a Promise". Closing as already resolved.

btravers avatar Jun 26 '26 15:06 btravers