📝 Bind the handler-map function in every example
Each README and JSDoc example now assigns the function that takes the handler object (the factory result, or the tagged key step) to a match… variable and reuses it, so the builder is created once instead of per call.
This commit is contained in:
1 parent
c8bee95088
commit
c878e60ff2
3 files changed
+20
-7
No files matched your search
@@ -111,7 +111,8 @@ const dispatch =
|
||||
* @typeParam T - The finite universe of primitive members to match.
|
||||
* @returns A builder for the handler map, or the handler map plus a fallback.
|
||||
* @example
|
||||
* const describe = getPrimitiveUnionMatcher<"yes" | "no">()({
|
||||
* const matchAnswer = getPrimitiveUnionMatcher<"yes" | "no">();
|
||||
* const describe = matchAnswer({
|
||||
* yes: () => "agreed",
|
||||
* no: () => "declined",
|
||||
* });
|
||||
@@ -133,7 +134,8 @@ export const getPrimitiveUnionMatcher = <
|
||||
* @typeParam T - The finite universe of primitive members to match.
|
||||
* @returns A builder for the handler map, or the handler map plus a fallback.
|
||||
* @example
|
||||
* const reply = getPrimitiveUnionMatcherW<"yes" | "no">()({
|
||||
* const matchReply = getPrimitiveUnionMatcherW<"yes" | "no">();
|
||||
* const reply = matchReply({
|
||||
* yes: () => 1,
|
||||
* no: () => "declined",
|
||||
* });
|
||||
|
||||
+4
-2
@@ -173,7 +173,8 @@ const dispatch =
|
||||
* | { kind: "circle"; radius: number }
|
||||
* | { kind: "square"; side: number };
|
||||
*
|
||||
* const area = getTaggedUnionMatcher<Shape>()("kind")({
|
||||
* const matchShape = getTaggedUnionMatcher<Shape>()("kind");
|
||||
* const area = matchShape({
|
||||
* circle: (s) => Math.PI * s.radius ** 2,
|
||||
* square: (s) => s.side ** 2,
|
||||
* });
|
||||
@@ -194,7 +195,8 @@ export const getTaggedUnionMatcher = <
|
||||
* @typeParam T - The discriminated-union type to match.
|
||||
* @returns A function that takes the discriminant property's name.
|
||||
* @example
|
||||
* const describe = getTaggedUnionMatcherW<Shape>()("kind")({
|
||||
* const matchShape = getTaggedUnionMatcherW<Shape>()("kind");
|
||||
* const describe = matchShape({
|
||||
* circle: () => "round",
|
||||
* square: () => 4,
|
||||
* });
|
||||
|
||||
Reference in new issue
Block a user