switch Patterns and Guards
Match shapes and add when conditions.
switch Meets Patterns
Modern Dart lets switch match patterns, not just constants. Each case can test the shape of a value and unpack it at once. 🔀
Matching a Record Shape
A case can be a record pattern. If the value matches that shape, the case runs and its fields bind to variables.
switch (point) {
case (0, 0): print('origin');
}All lessons in this course
- Records: Lightweight Tuples
- Positional and Named Record Fields
- Destructuring With Patterns
- switch Patterns and Guards