kotlin-patterns

Enforces idiomatic Kotlin patterns for null safety, coroutines, sealed classes, and DSL builders.

Updated May 19, 2026
One-click install
npx skills add https://github.com/azusagasaku/--claude-config --skill kotlin-patterns-azusagasaku
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-patterns
Source: https://github.com/azusagasaku/--claude-config/tree/main/skills/ecc/kotlin-patterns
Command: npx skills add https://github.com/azusagasaku/--claude-config --skill kotlin-patterns-azusagasaku

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Kotlin developers often write code that compiles but ignores the language's idioms, leading to null pointer crashes, mutable state bugs, unstructured concurrency, and verbose Java-style patterns that are hard to maintain. ## Core Features & Use Cases - Null Safety & Immutability: Enforces non-nullable types, safe-call operators, Elvis defaults, val over var, and copy()-based updates on data classes. - Structured Concurrency: Provides coroutine patterns using coroutineScope, supervisorScope, async/await, Flow operators, and proper cancellation handling. - Type-Safe Design: Covers sealed classes and interfaces for exhaustive when expressions, value classes for zero-overhead wrappers, extension functions, delegation, and @DslMarker DSL builders. - Use Case: When reviewing a pull request that uses GlobalScope.launch and force-unwraps nullable values with !!, apply this Skill to refactor the code toward structured concurrency and compiler-enforced null safety. ## Quick Start Review my Kotlin service class and refactor it to follow idiomatic patterns for null safety, coroutines, and sealed class error handling.

Frequently Asked Questions about kotlin-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle null safety in Kotlin idiomatically?▼

Use non-nullable types by default, safe-call operators (`?.`), and the Elvis operator (`?:`) for defaults. Avoid force-unwrapping with `!!`, which throws NPE; instead throw meaningful exceptions or return early when a value is absent.

How to run concurrent coroutines with structured concurrency in Kotlin?▼

Wrap parallel work in `coroutineScope` and launch children with `async`, then combine results with `await`. Use `supervisorScope` when child failures should not cancel siblings, and never use `GlobalScope.launch`.

When should I use a sealed class versus a sealed interface in Kotlin?▼

Use a sealed class when subtypes share state or constructors, such as a `Result<T>` type with Success, Failure, and Loading. Use a sealed interface for pure type hierarchies like API error models where subtypes only share behavior.

What is the difference between let, apply, also, run, and with in Kotlin?▼

`let` transforms a nullable value and returns the lambda result; `apply` configures an object and returns it; `also` adds side effects and returns the object; `run` and `with` execute a block on a receiver and return the result. Avoid nesting them deeply.

Why should I avoid GlobalScope in Kotlin coroutines?▼

GlobalScope launches coroutines outside any structured lifecycle, so they leak when the parent operation is cancelled or fails. Use `coroutineScope` or an injected scope so child coroutines are cancelled and cleaned up automatically.

When should I use Sequence instead of List operations in Kotlin?▼

Use `asSequence()` for large collections with multiple chained operations like filter and map, since sequences evaluate lazily without intermediate collections. For small lists or single operations, eager collection functions are simpler and faster.