What problem does it solve?
Kotlin codebases often accumulate tangled if/else chains, redundant casts, and non-exhaustive branches that hide bugs and resist refactoring. This Skill provides a structured procedure for choosing the right control-flow shape so the compiler proves correctness instead of the reader.
Core Features & Use Cases
- Branch shape selection: Decision table mapping code shapes to the right construct, including subject when, subjectless when, guard conditions, early returns, and exhaustive when expressions.
- Exhaustiveness and smart casts: Rules for naming every case in closed enums, sealed types, and nullable types while preserving smart-cast payloads without as, !!, or duplicate casts.
- Refactoring recipes: Concrete Kotlin examples showing guarded branches, null-as-branch classification, and when to keep else for open server or platform values.
- Use Case: While reviewing a pull request with a deeply nested if/else chain classifying UI events, apply the procedure to rewrite it as an exhaustive when with one guarded branch, then compile and test to confirm the refactor.
Quick Start
Ask the assistant to review this Kotlin when expression and refactor the branching logic using the kotlin-control-flow guidelines.