-
Notifications
You must be signed in to change notification settings - Fork 0
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
Custom Types #3
Labels
discussion
Ideas open for discussion
Comments
Open
A better alternative: const Msg = Type.custom({
Increment: [],
SetValue: [Type.int],
SetGreeting: [Type.string, Type.int],
});
const msg = Msg.Increment();
// Msg.SetValue(42);
// Msg.SetGreeting('Hello', 3);
Msg.match(msg, {
Increment() {
value = value + 1;
},
SetValue(newValue) {
value = newValue;
},
SetGreeting(greeting, times) {
value = String.repeat(greeting, times);
},
});
|
Though it should be feasible to have a default match as well: Msg.match(msg, {
Increment() {
value = value + 1;
},
_() {
// do some default action
},
}); |
And it should return the returned value: value = Msg.match({
Increment: () => value + 1,
// ...
}) |
Is |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Custom types are also known as "union types", "tagged unions" and "algebraic data types".
While typescript provides a way to have compile-time union types, they are no longer available at runtime, which means they can't be used for active behaviours (such as messages in
wool/browser
).Basic usage
Parameters
The text was updated successfully, but these errors were encountered: