kotlin-patterns

Apply idiomatic Kotlin patterns for null-safety, immutability, and coroutines.

1|Updated Mar 12, 2026
One-click install
npx skills add https://github.com/XiaoPuOuO/VFactory --skill kotlin-patterns-xiaopuouo
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-patterns
Source: https://github.com/XiaoPuOuO/VFactory/tree/main/paperclip-official/AgentSetting/skills/kotlin-patterns
Command: npx skills add https://github.com/XiaoPuOuO/VFactory --skill kotlin-patterns-xiaopuouo

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Kotlin developers often struggle to apply consistent, idiomatic patterns that ensure safety, readability, and maintainability across codebases.

Core Features & Use Cases

  • Null safety focus with type-safe patterns and safe-call usage
  • Immutability by default and data class design for value objects
  • Sealed classes and interfaces for exhaustive, safe type hierarchies
  • Structured concurrency with coroutines and Flow
  • Extension functions and DSL builders for expressive APIs
  • Guidance for Kotlin DSLs and Gradle Kotlin DSL usage

Quick Start

Refactor a sample module to apply idiomatic Kotlin patterns, focusing on null-safety, immutability, and clear coroutine usage.

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 for null safety and immutable data structures?

Idiomatic Kotlin code uses type-safe patterns and safe-call usage for null safety, alongside data class design for immutable value objects. This ensures robust code by defaulting to immutability and enforcing compile-time null checks.

What are the best practices for structured concurrency with Kotlin coroutines and Flow?

Best practices for Kotlin coroutines and Flow involve applying structured concurrency patterns to manage asynchronous scopes safely. This prevents memory leaks by ensuring child coroutines are scoped to parent lifecycles and properly canceled.

How do I use sealed classes and extension functions to build safe type hierarchies in Kotlin?

Sealed classes and interfaces create exhaustive, safe type hierarchies in Kotlin, while extension functions add expressive APIs without inheritance. Together they enable compile-time checks for exhaustive when statements and clean domain-specific logic.

Can I refactor existing Java libraries to use Kotlin DSL builders and structured concurrency?

Yes, you can refactor existing modules to apply idiomatic Kotlin patterns, focusing on null-safety, immutability, and clear coroutine usage. This transitions legacy code to structured concurrency and expressive DSL builder APIs.

When should I use Kotlin DSLs and Gradle Kotlin DSL for building expressive APIs?

Use Kotlin DSLs and Gradle Kotlin DSL when you need type-safe, expressive configuration APIs. They replace dynamic scripting with strongly-typed builders, improving readability and auto-completion while enforcing immutability and safe-call patterns.

Why does my Kotlin code fail to enforce exhaustive type checking in when statements?

Kotlin code fails to enforce exhaustive type checking when using open or abstract classes instead of sealed hierarchies. Applying sealed classes and interfaces ensures the compiler validates all possible branches in when statements.