by rokob · 5y ago · 0 comments
Dart is considering adding pattern matching (and real tuples!) and I think they will eventually get there. I just think that would have had to come first to make the case of optionals over nullable types more compelling.
I would call that example destructing in the normal sense and it is basically a form of pattern matching. To do that in an imperative language without pattern matching (i.e. what I am calling imperative destructuring), you end up with code like
if (maybeFoo.isSome) {
final foo = maybeFoo.asValue;
...
}
when you really want if let Some(foo) = maybeFoo {...} for foo in maybeFoo { ... }
This (AIUI) isn't valid Dart code though, but this would be: maybeFoo.forEach((foo) { ... })