3 ms·
>Dart has it, last 12 months or so. To clarify, in the above scenario in dart I can have an input with type MyEnum and do this? switch myEnum { case let one:
by RetpolineDrama 3y ago
>Dart has it, last 12 months or so.
To clarify, in the above scenario in dart I can have an input with type MyEnum and do this?
switch myEnum {
case let one:
// react to this here
case let two(twosChild: twosChild):
// call an API passing in a child element of twosChild here
case let three(threesGenericChild: threesGenericChild):
// T: Protocol, and call an extension function threesGenericChild.extension() here?
case let four(foursCallbackChild: foursCallbackChild):
// Pass foursCallbackChild callback into another context, and execute an escaping closure if needed?
}
Last I checked Dart required a nested if/else tree and didn't have compiler-guarantees of switch completeness like the above.
- refulgentis 3y agoCorrect, Dart has enum exhaustiveness checks, associated types, and expressions as of 11-13 months ago: https://cfdevelop.medium.com/dart-switch-expressions-33145c393052 https://cfdevelop.medium.com/dart-switch-expressions-33145c3... (keeping it short and simple because I'm at -2 on the original post, don't want to look like I'm argumentative)
- mraleph 3y agoIn Dart 3 you have patterns and sealed class families to achieve that. See my comment above[1]. The syntax is unfortunately more verbose, but if all goes well we will address that issue this year. [1]: https://news.ycombinator.com/item?id=39613415 https://news.ycombinator.com/item?id=39613415