kp-sealed-when
Installation
SKILL.md
One-line summary
Combine a sealed class or sealed interface (closed variant set) with an exhaustive when expression — getting compile-time-checked pattern matching that the compiler refuses to compile when a variant is unhandled.
When to use this skill
- Modeling a closed, finite set of variants: order status, parser results, command types, AST/expression nodes, network response shapes.
- Replacing
enumwhen variants need to carry different data (an enum is a set of singletons; a sealed hierarchy is variants-with-payload). - Implementing GoF State, Visitor, or Command patterns in idiomatic Kotlin.
- Wherever you have a "type code + switch" pattern in older code — sealed + when is the structural fix.
When NOT to use this skill
- The set is genuinely open-ended (third parties or downstream modules can add new variants) — use an open interface instead.
- The variants share no behavior or data — they might not belong as a hierarchy at all. Consider whether the discriminator is the wrong abstraction.
- A simple
enumsuffices because the variants are pure tags with no payload.