kotlin-patterns

Enforce idiomatic Kotlin patterns for null safety, immutability, and DSL builders.

1|Updated Jan 30, 2021
One-click install
npx skills add https://github.com/fideguch/my_dotfiles --skill kotlin-patterns-fideguch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-patterns
Source: https://github.com/fideguch/my_dotfiles/tree/main/claude/skills/kotlin-patterns
Command: npx skills add https://github.com/fideguch/my_dotfiles --skill kotlin-patterns-fideguch

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This guide helps developers write idiomatic, safe, and maintainable Kotlin by consolidating patterns for null safety, immutability, sealed hierarchies, coroutines, extension functions, and DSL builders.

Core Features & Use Cases

  • Enforces null safety through Kotlin's type system and safe calls.
  • Encourages immutability by default and data-class usage for value objects.
  • Introduces and documents DSL builders and type-safe patterns for clean APIs.
  • Covers structured concurrency, flows, and extension functions to compose robust modular code.
  • Includes examples and best practices for Gradle Kotlin DSL and Kotlin code organization.

Quick Start

Apply idiomatic Kotlin patterns in a sample module to enforce null safety, immutability, and DSL patterns.

Frequently Asked Questions about kotlin-patterns

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

FAQPage Schema
How do I enforce null safety and immutability in Kotlin?

Enforce null safety in Kotlin by applying the type system with safe calls, and default to immutability using data classes for value objects. This prevents runtime null pointer exceptions and produces robust, maintainable code.

When should I use sealed hierarchies and DSL builders in Kotlin?

Use sealed hierarchies and DSL builders in Kotlin when designing type-safe, clean APIs. They enforce restricted class hierarchies and enable expressive domain-specific languages for robust module architecture.

What's the best way to manage structured concurrency with Kotlin coroutines?

Manage structured concurrency with Kotlin coroutines by applying structured patterns and flows. This ensures background tasks are properly scoped and cancelled, producing robust modular code with clear usage of language features.

Can I use Kotlin patterns for Gradle build configuration?

Yes, you can apply idiomatic Kotlin patterns for Gradle build configuration. The guide includes best practices and examples for Gradle Kotlin DSL to organize builds cleanly.

How do I write idiomatic Kotlin extension functions for modular code?

Write idiomatic Kotlin extension functions to compose robust modular code by adding functionality to existing classes without inheritance. This pattern supports clean API design and maintainable code organization.

Why does Kotlin encourage data class usage for value objects?

Kotlin encourages data class usage for value objects to enforce immutability by default and reduce boilerplate. Data classes automatically generate equals, hashCode, and copy methods for type-safe API requirements.