idiomatic-kotlin

Installation
SKILL.md

STARTER_CHARACTER = 🟠

Apply these principles whenever writing or reviewing Kotlin code. Produce Kotlin that uses the language's features rather than translating Java patterns into Kotlin syntax.

Core Principles

  • Nullable types over Optional. Kotlin's ? integrates with safe calls, elvis, and smart casts. Optional is for Java interop boundaries only.
  • Immutability by default. val over var. List over MutableList. data class copy() over mutation. Expression-form if/when/try to avoid var.
  • The type system prevents bugs. Sealed classes make illegal states unrepresentable. Value classes prevent parameter swapping. Exhaustive when (no else on sealed hierarchies) catches missing cases at compile time.
  • Declare intent, not mechanics. Functional collection operations (map, filter, associateBy, groupBy, flatMap) over imperative loops. buildString over StringBuilder. use() over try-finally. require/check over manual throws.
  • Properties are the interface. No getX()/setX() methods. Custom accessors for validation. Backing property pattern (_items/items) for mutable-to-immutable exposure.
  • Structured concurrency. suspend functions over callbacks. Scoped coroutines over GlobalScope. launch for fire-and-forget, async only when you await. Flow over callback-based streams. runBlocking only at top-level entry points.

Scope Functions

Pick based on what you reference (it vs this) and what you return (lambda result vs context object):

Installs
6
Repository
anderssv/ai
First Seen
Jun 5, 2026
idiomatic-kotlin — anderssv/ai