kotlin-patterns

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

Updated Apr 18, 2026
One-click install
npx skills add https://github.com/JohnRebellion/.claude-public --skill kotlin-patterns-johnrebellion
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-patterns
Source: https://github.com/JohnRebellion/.claude-public/tree/main/claude/skills/kotlin-patterns
Command: npx skills add https://github.com/JohnRebellion/.claude-public --skill kotlin-patterns-johnrebellion

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Kotlin code that is merely functional often leads to null pointer exceptions, mutable state bugs, and unstructured concurrency. This Skill provides a comprehensive set of idiomatic Kotlin patterns so that code written or reviewed by the AI follows the language's best practices for safety, immutability, and maintainability. ## Core Features & Use Cases - Null Safety & Immutability: Enforces non-nullable types, safe-call operators, Elvis operator, val over var, and copy()-based updates on data classes. - Structured Concurrency: Provides patterns for coroutineScope, supervisorScope, async/await, Flow streams, and proper cancellation handling with ensureActive() and NonCancellable cleanup. - Type-Safe Design: Covers sealed classes and interfaces for exhaustive when expressions, @JvmInline value class wrappers, extension functions, delegation with by, and @DslMarker-annotated DSL builders. - Use Case: When refactoring a Kotlin service that uses GlobalScope.launch and force-unwrapped nullables, this Skill guides the rewrite toward structured concurrency with coroutineScope and safe-call chains, plus a Gradle Kotlin DSL build configuration. ## Quick Start Review my Kotlin file and refactor it to follow idiomatic patterns for null safety, immutability, and structured concurrency.

Frequently Asked Questions about kotlin-patterns

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

FAQPage Schema
How do I write idiomatic Kotlin code with null safety?▼

Use non-nullable types by default, safe-call operators (?.) for nullable access, and the Elvis operator (?:) for default values. Avoid force-unwrapping with !! and prefer throwing descriptive exceptions or returning null explicitly.

How to use Kotlin coroutines for concurrent tasks?▼

Wrap concurrent work in coroutineScope and launch child jobs with async, then combine results with await. Use supervisorScope when child failures should not cancel siblings, and never use GlobalScope for application work.

When should I use sealed classes vs sealed interfaces in Kotlin?▼

Use sealed classes for restricted hierarchies with shared state, such as a Result type with Success, Failure, and Loading variants. Use sealed interfaces when implementations need multiple inheritance or are unrelated types sharing a common contract like ApiError.

Does Kotlin Flow handle errors and cancellation automatically?▼

Flow propagates cancellation through the coroutine context, but errors must be handled explicitly with the catch operator. Always rethrow CancellationException and use withContext(NonCancellable) inside finally blocks for resource cleanup.

What are the limitations of Kotlin scope functions like let and apply?▼

Nesting scope functions such as let inside let creates unreadable code and shadowed implicit receivers. Prefer chaining safe calls directly and reserve scope functions for single-level transformations, configuration, or side effects.