kotlin-patterns

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

Updated Mar 25, 2026
One-click install
npx skills add https://github.com/Femad-6/my-skills --skill kotlin-patterns-femad-6
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-patterns
Source: https://github.com/Femad-6/my-skills/tree/main/.github/skills/kotlin-patterns
Command: npx skills add https://github.com/Femad-6/my-skills --skill kotlin-patterns-femad-6

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 conventions so code reviews, refactoring, and new development consistently follow best practices. ## Core Features & Use Cases - Null Safety & Immutability: Enforces non-nullable types, safe-call operators, val over var, and copy()-based updates on data classes. - Structured Concurrency: Guides correct use of coroutineScope, supervisorScope, async/await, Flow operators, and cancellation-aware cleanup. - Type-Safe Design: Covers sealed classes and interfaces for exhaustive when expressions, value classes for zero-overhead wrappers, and @DslMarker DSL builders. - Use Case: When reviewing a Kotlin service that uses GlobalScope.launch and force-unwrapped nullables, apply this Skill to refactor toward structured concurrency and safe-call chains. ## Quick Start Ask the assistant to review or write Kotlin code following idiomatic patterns for null safety, coroutines, and sealed class hierarchies.

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 (?.) for nullable access, and the Elvis operator (?:) for defaults. Avoid force-unwrapping with !! since it throws NullPointerException; throw descriptive exceptions or return nullables instead.

How to run concurrent coroutines with structured concurrency in Kotlin?

Wrap concurrent work in coroutineScope and launch child tasks with async, then combine results with await. Use supervisorScope when child failures should not cancel siblings, and never use GlobalScope since it breaks structured concurrency.

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. Use sealed interfaces when implementations need multiple inheritance, like modeling API error types with a common message property.

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 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, and mapLatest operators for search-as-you-type pipelines. Attach a catch operator to handle upstream errors and emit fallback values like empty lists.

When should I avoid using Kotlin sequences?

Avoid sequences for small collections or single operations, since the iterator overhead outweighs lazy evaluation benefits. Sequences pay off for large collections with multiple chained operations like filter, map, and take.