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.Optionalis for Java interop boundaries only. - Immutability by default.
valovervar.ListoverMutableList.data class copy()over mutation. Expression-formif/when/tryto avoidvar. - The type system prevents bugs. Sealed classes make illegal states unrepresentable. Value classes prevent parameter swapping. Exhaustive
when(noelseon sealed hierarchies) catches missing cases at compile time. - Declare intent, not mechanics. Functional collection operations (
map,filter,associateBy,groupBy,flatMap) over imperative loops.buildStringoverStringBuilder.use()over try-finally.require/checkover 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.
suspendfunctions over callbacks. Scoped coroutines overGlobalScope.launchfor fire-and-forget,asynconly when youawait.Flowover callback-based streams.runBlockingonly 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):