From 09e1c122700940913f62a0f6116555608adab938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Tue, 22 Sep 2026 10:57:03 +0000 Subject: [PATCH] :recycle: Return dispatch tacitly from the tagged-union factory --- src/tagged-union.ts | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/tagged-union.ts b/src/tagged-union.ts index 26b0a00..69aa65b 100644 --- a/src/tagged-union.ts +++ b/src/tagged-union.ts @@ -99,6 +99,17 @@ interface TaggedUnionMatcherWidening { ): UnaryFn | R>; } +// The key-taking step of the curried factory. Naming it lets the factory return +// `dispatch` directly, the tacit twin of the primitive-union factory's bare +// `=> dispatch`. +interface TaggedUnionMatcherFactory { + >(k: K): TaggedUnionMatcherStrict; +} + +interface TaggedUnionMatcherWideningFactory { + >(k: K): TaggedUnionMatcherWidening; +} + const dispatch = (k: PropertyKey) => (handlers: HandlerMap, fallback?: UnaryFn) => @@ -120,12 +131,10 @@ const dispatch = ); }; -export const getTaggedUnionMatcher = - () => - >(k: K): TaggedUnionMatcherStrict => - dispatch(k); +export const getTaggedUnionMatcher = < + T extends object, +>(): TaggedUnionMatcherFactory => dispatch; -export const getTaggedUnionMatcherW = - () => - >(k: K): TaggedUnionMatcherWidening => - dispatch(k); +export const getTaggedUnionMatcherW = < + T extends object, +>(): TaggedUnionMatcherWideningFactory => dispatch;