dart-use-pattern-matching
Installation
SKILL.md
Contents
- Pattern Selection Strategy
- Switch Expressions vs Switch Statements
- Core Pattern Syntaxes
- Workflow: Designing Pattern Matching Logic
- Examples
Pattern Selection Strategy
Apply distinct pattern matching strategies based on the target data structure:
- JSON Validation and Destructuring: Use Map and List patterns to simultaneously validate nested shapes and bind values to local variables in a single step.
- Multiple Returns: Return Records from functions and use Record patterns to destructure named or positional values directly into scoped variables.
- Algebraic Data Types (ADTs): Combine
sealedclass hierarchies with Object patterns in switch expressions to benefit from compile-time exhaustiveness checking. - Numeric Ranges and logical Checks: Combine relational patterns (
>=,<, etc.) and logical-and (&&) or logical-or (||) operators within switch cases. - Guard Clauses: Use the
whenkeyword to assert dynamic conditions that cannot be expressed purely through static patterns.