♻️ Return dispatch tacitly from the tagged-union factory
This commit is contained in:
1 parent
6228b4922d
commit
09e1c12270
1 file changed
+17
-8
+17
-8
@@ -99,6 +99,17 @@ interface TaggedUnionMatcherWidening<T extends object, K extends keyof T> {
|
||||
): UnaryFn<T, PatternReturns<Handled> | 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<T extends object> {
|
||||
<K extends Discriminated<T>>(k: K): TaggedUnionMatcherStrict<T, K>;
|
||||
}
|
||||
|
||||
interface TaggedUnionMatcherWideningFactory<T extends object> {
|
||||
<K extends Discriminated<T>>(k: K): TaggedUnionMatcherWidening<T, K>;
|
||||
}
|
||||
|
||||
const dispatch =
|
||||
(k: PropertyKey) =>
|
||||
(handlers: HandlerMap, fallback?: UnaryFn<never, unknown>) =>
|
||||
@@ -120,12 +131,10 @@ const dispatch =
|
||||
);
|
||||
};
|
||||
|
||||
export const getTaggedUnionMatcher =
|
||||
<T extends object>() =>
|
||||
<K extends Discriminated<T>>(k: K): TaggedUnionMatcherStrict<T, K> =>
|
||||
dispatch(k);
|
||||
export const getTaggedUnionMatcher = <
|
||||
T extends object,
|
||||
>(): TaggedUnionMatcherFactory<T> => dispatch;
|
||||
|
||||
export const getTaggedUnionMatcherW =
|
||||
<T extends object>() =>
|
||||
<K extends Discriminated<T>>(k: K): TaggedUnionMatcherWidening<T, K> =>
|
||||
dispatch(k);
|
||||
export const getTaggedUnionMatcherW = <
|
||||
T extends object,
|
||||
>(): TaggedUnionMatcherWideningFactory<T> => dispatch;
|
||||
Reference in new issue
Block a user