kotlin-patterns

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

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/freedom909/real-estate-saas --skill kotlin-patterns-freedom909
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-patterns
Source: https://github.com/freedom909/real-estate-saas/tree/main/.trae/skills/kotlin-patterns
Command: npx skills add https://github.com/freedom909/real-estate-saas --skill kotlin-patterns-freedom909

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: 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 type wrappers, and @DslMarker-based DSL builders. - Use Case: When refactoring a Kotlin service that uses GlobalScope.launch and force-unwrapped nullables, this Skill rewrites it with structured concurrency, Result-based error handling, and null-safe call chains. ## Quick Start Review my Kotlin repository code and refactor it to follow idiomatic Kotlin patterns including null safety, coroutines, and sealed classes.

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?▼

Kotlin null safety relies on non-nullable types by default, safe-call operators (?.), and the Elvis operator (?:) for defaults. Avoid force-unwrapping with !! and use require or check for preconditions with clear error messages.

How to use Kotlin coroutines for concurrent tasks?▼

Use coroutineScope with async and await to run tasks concurrently under structured concurrency. Use supervisorScope when child tasks can fail independently, and always call ensureActive before expensive work to respect cancellation.

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

Sealed classes suit restricted state hierarchies like Result types with Success, Failure, and Loading variants. Sealed interfaces work better for API error models where implementations need flexible inheritance while keeping when expressions exhaustive.

What is the difference between Flow and Sequence in Kotlin?▼

Flow is a cold reactive stream for asynchronous data with operators like debounce and mapLatest, integrated with coroutines. Sequence provides lazy synchronous evaluation for large collections with multiple chained operations.

Why should I avoid GlobalScope in Kotlin coroutines?▼

GlobalScope launches coroutines outside any structured lifecycle, causing leaks and uncontrolled cancellation. Use coroutineScope or an injected application scope so child coroutines are cancelled when their parent completes or fails.

Does this Kotlin style guide work with Gradle Kotlin DSL?▼

Yes, it includes build.gradle.kts configuration covering Kotlin JVM plugins, jvmToolchain settings, Ktor and Exposed dependencies, Kotest testing, and detekt static analysis setup.