kotlin-patterns

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

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill kotlin-patterns-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-patterns
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/kotlin-patterns
Command: npx skills add https://github.com/ibytechaos/claude --skill kotlin-patterns-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Kotlin codebases often drift into non-idiomatic patterns like force-unwrapping nullables, mutable state, unstructured concurrency, and Java-style verbosity. This Skill provides concrete conventions and code examples so Kotlin code stays null-safe, immutable, and maintainable across writing, reviewing, and refactoring tasks. ## 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: Guides coroutine usage with coroutineScope, supervisorScope, Flow operators, cancellation handling, and cleanup via NonCancellable blocks. - Type-Safe Design: Covers sealed classes and interfaces for exhaustive when expressions, @JvmInline value classes, extension functions, delegation with by, and @DslMarker DSL builders. - Use Case: When reviewing a Kotlin service that uses GlobalScope.launch and !! operators, apply this Skill to refactor toward structured concurrency and compiler-enforced null safety. ## Quick Start Review my Kotlin repository code 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 idiomatically in Kotlin?

Use non-nullable types by default, safe-call operators (?.), and the Elvis operator (?:) for defaults. Avoid force-unwrapping with !! since it throws NPE; instead throw descriptive exceptions or return nullable types from lookups.

How to run concurrent coroutines in Kotlin with structured concurrency?

Wrap parallel 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 spread across class hierarchies, like API error types.

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

let transforms a nullable or scoped result, apply configures an object and returns it, also adds side effects while returning the object, and run or with execute a block on a receiver returning the result. Avoid nesting scope functions; chain safe calls instead.

Does Kotlin Flow support debounce and error handling for search?

Yes, Flow supports debounce, distinctUntilChanged, filter, and mapLatest operators for search pipelines, plus catch for error handling. A typical pattern debounces query input by 300ms, filters short queries, and emits empty lists on errors.

When should I avoid using Kotlin sequences?

Sequences add overhead for small collections or single operations, so use them only for large collections with multiple chained operations like filter plus map plus take. For simple one-pass operations on small lists, eager collection operations are cheaper.