hearth-case-class-rules

Derive Scala type class instances from case classes using Hearth CaseClass.parse.

68|7|Updated Nov 24, 2025
One-click install
npx skills add https://github.com/kubuszok/kindlings --skill hearth-case-class-rules
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hearth-case-class-rules
Source: https://github.com/kubuszok/kindlings/tree/main/docs/contributing/hearth-case-class-rules
Command: npx skills add https://github.com/kubuszok/kindlings --skill hearth-case-class-rules

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Deriving type class instances for Scala case classes often requires boilerplate and repeated patterns. This skill provides structured rules and patterns for automatic derivation using Hearth's CaseClass.parse, supporting both encoder-style field reading and decoder-style construction, while handling existential types and nested structures.

Core Features & Use Cases

  • Encoder-style derivation using CaseClass.parse to read case class fields and derive instances.
  • Decoder-style construction using primaryConstructor and field maps for building instances from decoded fields.
  • Advanced patterns for existential types, LambdaBuilder usage, and cache-aware strategies like nest vs nestInCache.
  • Guidance for dual-path derivation with a runtime flag to support fail-fast vs error-accumulating workflows.
  • Practical use cases include deriving encoders/decoders for ADTs, nested case classes, and mixed field types with minimal boilerplate.

Quick Start

Derive a type class for a sample case class using CaseClass.parse to see encoder/decoder paths.

Frequently Asked Questions about hearth-case-class-rules

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

FAQPage Schema
How do I derive type class instances for Scala case classes without boilerplate?

Hearth's CaseClass.parse API automates type class derivation for Scala case classes by applying encoder-style field reading and decoder-style construction patterns. It leverages primaryConstructor and field maps to eliminate manual boilerplate and generate type-safe instances.

What is the best way to handle nested case classes and existential types in Scala type class derivation?

Handling nested structures and existential types in Scala type class derivation requires advanced patterns like LambdaBuilder and cache-aware strategies. Using nest versus nestInCache ensures type-safe, cache-friendly derivations for complex nested case classes and mixed field types.

Can I support both fail-fast and error-accumulating validation when deriving Scala decoders?

Yes, dual-path derivation with a runtime flag supports both fail-fast and error-accumulating workflows when constructing Scala case class instances. This allows decoders to either stop at the first error or collect all validation errors during field mapping.

How does encoder-style derivation differ from decoder-style construction for Scala case classes?

Encoder-style derivation uses CaseClass.parse to read case class fields and extract data, while decoder-style construction uses primaryConstructor and field maps to build instances from decoded values. Both approaches minimize boilerplate but serve opposite data flow directions for type class instances.

When do I need cache-aware derivation strategies for Scala type classes?

Cache-aware derivation strategies like nestInCache are needed when deriving type class instances for nested Scala case classes or ADTs with repeated structures. These patterns prevent redundant derivation overhead and ensure efficient, reusable instances for complex existential types and mixed field types.