All skills
Skillintermediate

Kotlin Patterns

> This file extends the common patterns rule with Kotlin-specific content.

Claude Code Knowledge Pack7/10/2026

Overview

Kotlin Patterns

This file extends the common patterns rule with Kotlin-specific content.

Sealed Classes

Use sealed classes/interfaces for exhaustive type hierarchies:

sealed class Result<out T> {
    data class Success(val data: T) : Result()
    data class Failure(val error: AppError) : Result()
}

Extension Functions

Add behavior without inheritance, scoped to where they're used:

fun String.toSlug(): String =
    lowercase().replace(Regex("[^a-z0-9\\\\s-]"), "").replace(Regex("\\\\s+"), "-")

Scope Functions

  • let: Transform nullable or scoped result
  • apply: Configure an object
  • also: Side effects
  • Avoid nesting scope functions

Dependency Injection

Use Koin for DI in Ktor projects:

val appModule = module {
    single { ExposedUserRepository(get()) }
    single { UserService(get()) }
}

Reference

See skill: kotlin-patterns for comprehensive Kotlin patterns including coroutines, DSL builders, and delegation.