sealed-results

Models UI states and typed operation results in Kotlin using sealed classes and Result.

Updated May 9, 2026
One-click install
npx skills add https://github.com/Bumh3rr/solvyx-app --skill sealed-results-bumh3rr
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: sealed-results
Source: https://github.com/Bumh3rr/solvyx-app/tree/main/.opencode/skill/sealed-results
Command: npx skills add https://github.com/Bumh3rr/solvyx-app --skill sealed-results-bumh3rr

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Kotlin Android codebases often leak exceptions to the UI, use nullable states, or rely on generic error handling that makes ViewModels inconsistent and hard to maintain. This Skill provides consistent patterns for modeling UI states and operation results with sealed classes and Result. ## Core Features & Use Cases - UI State Modeling: Define sealed interfaces for screen states (Loading, Loaded, Error, Empty) consumed by Jetpack Compose with exhaustive when expressions. - Typed Operation Results: Choose between Result<T> for simple success/failure and sealed classes for errors requiring differentiated UI handling. - Exception Mapping: Convert SQLiteException, IOException, and other throwables into user-friendly messages before they reach the UI layer. - Use Case: When building a ViewModel for a form screen in a Hilt-based Android app, apply these patterns to expose a StateFlow of sealed UI states and map repository results into specific error cases like invalid dates or overly long notes. ## Quick Start Apply the sealed-results patterns to design the UiState sealed interface and repository result types for my Kotlin ViewModel.

Frequently Asked Questions about sealed-results

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

FAQPage Schema
How do I model UI state with sealed classes in Kotlin?▼

Define a sealed interface with object and data class subclasses for each state such as Loading, Loaded, and Error. Expose it from the ViewModel as a StateFlow and render it in Compose with an exhaustive when expression.

When should I use Result<T> vs sealed class for errors in Kotlin?▼

Use Result<T> when you only need to know whether an operation succeeded or failed. Use a sealed class when the ViewModel must react differently per error type, such as showing distinct messages for invalid dates versus database failures.

How do I handle exceptions in an Android ViewModel with StateFlow?▼

Catch exceptions in the repository or use Flow's catch operator, then map them to an Error state or a user-friendly message. Never let a Throwable escape to the UI layer; convert it with a helper like a Throwable.toUserMessage() when-expression.

Does this sealed state pattern work with Jetpack Compose?▼

Yes. Collect the StateFlow with collectAsStateWithLifecycle and use a when expression over the sealed interface to render Loading, Loaded, or Error composables. Exhaustive when ensures every state is handled at compile time.

When should I avoid sealed classes for UI state?▼

Avoid sealed classes when there is only one case (use a data class), when errors only need a success/failure signal (use Result<T>), or when the ViewModel always responds identically to every failure. Also avoid mixing Result with sealed types without a clear reason.