♻️ 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>;
|
): 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 =
|
const dispatch =
|
||||||
(k: PropertyKey) =>
|
(k: PropertyKey) =>
|
||||||
(handlers: HandlerMap, fallback?: UnaryFn<never, unknown>) =>
|
(handlers: HandlerMap, fallback?: UnaryFn<never, unknown>) =>
|
||||||
@@ -120,12 +131,10 @@ const dispatch =
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getTaggedUnionMatcher =
|
export const getTaggedUnionMatcher = <
|
||||||
<T extends object>() =>
|
T extends object,
|
||||||
<K extends Discriminated<T>>(k: K): TaggedUnionMatcherStrict<T, K> =>
|
>(): TaggedUnionMatcherFactory<T> => dispatch;
|
||||||
dispatch(k);
|
|
||||||
|
|
||||||
export const getTaggedUnionMatcherW =
|
export const getTaggedUnionMatcherW = <
|
||||||
<T extends object>() =>
|
T extends object,
|
||||||
<K extends Discriminated<T>>(k: K): TaggedUnionMatcherWidening<T, K> =>
|
>(): TaggedUnionMatcherWideningFactory<T> => dispatch;
|
||||||
dispatch(k);
|
|
||||||
Reference in new issue
Block a user