Skip to content

Instantly share code, notes, and snippets.

View jul-sh's full-sized avatar

jul-sh jul-sh

  • Google DeepMind
  • New York City
  • 23:49 (UTC -04:00)
View GitHub Profile
This skill is expanded to be language-agnostic, anchoring the concept in **Algebraic Data Types (Sum Types)**. This provides the theoretical basis for *why* this prevents bugs (math/cardinality) and provides concrete implementation patterns for modern languages like Rust, TypeScript, Python, and Kotlin.
---
---
## name: enum-driven-state description: Enforce type-safe state modeling using Sum Types (Enums, Discriminated Unions, Sealed Classes) to make invalid states unrepresentable. Refactor parallel booleans, nullable "conditional" fields, and loose flags into exclusive cases with associated data.
# Enum-Driven State (Make Invalid States Unrepresentable)
@jul-sh
jul-sh / skill.md
Created January 9, 2026 18:59
Enum-Driven State: Refactoring and Authoring guides

Enum-Driven State

A behavior-preserving refactor that makes unintended states structurally impossible using Sum Types (Enums, Discriminated Unions, Sealed Classes).


Core Principles

  1. Make Illegal States Unrepresentable: Structure types so invalid combinations cannot compile—no runtime validation or comments needed.
  2. Sum Types over Product Types: Replace structs with optional fields (status, data?, error?) with enums where each variant holds exactly what it needs.
  3. Pattern Matching: Replace boolean checks (if isX) with exhaustive match/switch. Adding a new state forces compiler errors at all call sites.