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 enum when 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 enum suffices because the variants are pure tags with no payload.

Core content

Installs
1
GitHub Stars
1
First Seen
Jul 13, 2026
kp-sealed-when — yonatankarp/software-design-skills