-
-
Notifications
You must be signed in to change notification settings - Fork 160
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] runtime match with type #1348
Comments
If I have a chance, I'd like to work on it. |
You can start from the Also, instead of making both matches and asserMatches functions at the same time, I think the last callback function should be the error handler. If the last function be skipped, it throws error. If your contribution comes after v7 release, this feature would come in v7.1 minor update. https://github.com/samchon/typia/tree/v7.0/src/programmers/functional |
oh.. thanks! const result = match(1 as 1 | 2 | 3 | 4,
(src: 1) => "one",
(src: 2 | 3) => "two or three",
(err: UnmatchedError) => e.toString()
);
result;
// ^? const result: "one" | "two or three" | string
const result2 = matchAssert(4 as 1 | 2 | 3 | 4,
(src: 1) => "one",
(src: 2 | 3) => "two or three"
);
// expected assertsion error! |
Yes it is. I think |
It's a feature that looks like a lot of fun! I will use this function very often if it is added. This feature is also larger than other libraries. ( But it can also confuse a lot of people when it's an object type. If there are people who can't distinguish subtypes. ) |
Feature Request
typia has been used so far to verify types or to give random values.
And now I think I can manage the work after the verification, not the verification.
ts-pattern and pattycake resemble a pattern match of rust or c#, for which we take the pattern as a function factor value.
In the case of typia, you can take the type as a factor and convert it into an if statement in advance at compilation time.
You just have to write the verification syntax into a type and give it to the user how to handle the verified type
How to use?
just write
match
After compilation, it changes to a native conditional statement.
Similar library?
Effect.match
ts-pattern.match
pattycake.match
Of the following, only patty-cake is changes native at compilation time.
but the form will be very different from typia.match.
This is because typia can use pre-declared types so that you don't have to rewrite the match case.
The text was updated successfully, but these errors were encountered: