-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Replace when
and maybeWhen
with pattern matching in Dart 3
#333
Comments
👋 @satvikpendem This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here. |
Thanks for raising this suggestion! I've been meaning to take a look at what faff we can remove and this seems like a good option. |
I'm curious - if this is tackled, will it remove the need to also specify an If a given object can only be one of 2 object-types, it feels odd that we always have to provide an
Which works fine but is a little silly. |
Providing the `orElse` even when all other cases have been “checked” is
useful if you want to build future-proof apps. It will allow you to add a
new type to your API without breaking existing apps.
Say that you add a type called `ObjectType3` in your example, this would
throw an exception. You can then add a new case, but depending on your set
up, you might not be able to ensure that all your clients are updated.
…On Thu, 6 Jun 2024 at 17:50, Greg Coladarci ***@***.***> wrote:
I'm curious - if this is tackled, will it remove the need to also specify
an orElse equivalent?
If a given object can *only be* one of 2 object-types, it feels odd that
we always have to provide an orElse. To get around this we do this in
many, many places :)
thing.when(
objectTypeOne: (one) => ...,
objectTypeTwo: (two) => ...,
orElse: () => throw Exception('Can not happen.'),
);
Which works fine but is a little silly.
—
Reply to this email directly, view it on GitHub
<#333 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA2UFS5AOCH4P7DWNLNU7O3ZGCHNDAVCNFSM6AAAAABI5DQFA6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNJSHE3TSMJSGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Thank you for this - a very good reason to have this, indeed... |
Now that Dart 3 is here, you can likely replace the above two functions without loss of functionality, as
freezed
has also done here:The text was updated successfully, but these errors were encountered: