kotlin-expert

Codify advanced Kotlin patterns for state management and type safety.

1.6k|218|Updated Jan 11, 2023
One-click install
npx skills add https://github.com/vitorpamplona/amethyst --skill kotlin-expert-vitorpamplona
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-expert
Source: https://github.com/vitorpamplona/amethyst/tree/main/.claude/skills/kotlin-expert
Command: npx skills add https://github.com/vitorpamplona/amethyst --skill kotlin-expert-vitorpamplona

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This guide helps Amethyst developers apply advanced Kotlin idioms—StateFlow/SharedFlow for robust state and event handling, sealed hierarchies for exhaustive modeling, @Immutable-based Compose optimization, DSL builders for readable APIs, and inline/reified patterns for performance—across multiplatform codebases.

Core Features & Use Cases

  • State management patterns with StateFlow/SharedFlow to model UI state and events in a scalable way.
  • Sealed hierarchies (sealed classes and sealed interfaces) to model distinct UI states and generic results with exhaustiveness.
  • Immutability and Compose performance practices using @Immutable, data classes, and kotlinx.collections.immutable.
  • DSL builders and type-safe DSLs to build domain objects and configurations succinctly.
  • Inline and reified patterns to reduce allocation and enable runtime type checks in hot paths.

Quick Start

Create a tiny Kotlin module that demonstrates a StateFlow-based UI state, a sealed class for view states, and an immutable data class, then observe updates in a simple Compose-like flow.

Frequently Asked Questions about kotlin-expert

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

FAQPage Schema
How do I use StateFlow and SharedFlow for scalable Kotlin UI state management?

Use StateFlow to model distinct UI state values and SharedFlow to handle one-off events, enabling scalable state management across Kotlin multiplatform codebases. This pattern ensures robust state emission and event handling without redundant allocations.

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

Use sealed classes for rigid hierarchical state modeling and sealed interfaces for flexible, multi-platform generic results. Sealed interfaces allow multiplatform codebases to share exhaustive state definitions across different targets without rigid class constraints.

How do I optimize Compose performance with @Immutable and immutable collections in Kotlin?

Apply the @Immutable annotation to data classes and utilize kotlinx.collections.immutable for read-only collections. This prevents unnecessary recompositions in Compose-enabled UI by ensuring type safety and structural immutability across multiplatform targets.

What is the best way to build domain configurations using Kotlin DSL builders?

Use type-safe Kotlin DSL builders to construct domain objects and configurations succinctly. This approach leverages Kotlin's type system to create readable APIs, ensuring compile-time validation and reducing boilerplate code across multiplatform modules.

Do I need inline and reified patterns to reduce Kotlin allocation in hot paths?

Yes, applying inline and reified patterns in hot paths reduces memory allocation and enables runtime type checks without reflection overhead. This significantly improves multiplatform Kotlin performance by generating specialized bytecode at call sites.

Can I apply these Kotlin multiplatform patterns in any project or are they Amethyst specific?

While these advanced Kotlin idioms are codified from Amethyst's state management and type safety practices, the patterns for StateFlow, sealed hierarchies, and immutability apply directly to any Kotlin multiplatform codebase utilizing Compose.