← ClaudeAtlas

kotlin-functional-programminglisted

Guides writing idiomatic, functional-style Kotlin code using built-in language features. Use when asked to write, review, or refactor Kotlin code for immutability, pure functions, sealed types, error handling, collections, coroutines, or functional architecture patterns.
msewell/agent-stuff · ★ 0 · Code & Development · score 70
Install: claude install-skill msewell/agent-stuff
# Kotlin Functional Programming ## Workflow 1. Read the relevant reference file(s) from `references/` before advising (see References section below for which file covers which topics). 2. Identify which principles apply to the user's code or question (see Summary of Principles in the reference). 3. Apply the relevant best practices; cite section numbers when explaining trade-offs. 4. Prefer Kotlin built-in features over third-party libraries unless the user explicitly asks otherwise. 5. Validate suggestions against the Kotlin 2.0–2.2+ feature set described in the reference. 6. When refactoring existing code, make the smallest change that moves toward the functional core, imperative shell architecture. ## Key Principles (quick reference) - Default to `val`; treat `var` as a code smell requiring justification. - Write pure functions for all domain logic; push I/O and mutation to the edges. - Use `if`, `when`, `try` as expressions that return values assigned to `val`. - Model variants with `sealed interface`; never add `else` to an exhaustive `when`. - Wrap primitives in `@JvmInline value class` to prevent argument-order bugs at zero runtime cost. - Handle expected failures with `T?`, `Result<T>`, or sealed error hierarchies — not exceptions. - Compose behavior with higher-order functions; use `inline` on lambda-taking utilities to eliminate allocation overhead. - Build data pipelines with collection operators (`map`, `filter`, `fold`, `flatMap`, …). - Default to eager collect