kindlings-factory-instance

Replace per-type anonymous class emissions with reusable factory methods in macro-generated type class derivations.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Factory instance pattern replaces heavy per-type anonymous class emissions in macro-generated type class derivations with single, reusable factory methods. This reduces the number of generated .class files, speeds up compilation, and simplifies the runtime footprint when deriving for many types.

Core Features & Use Cases

  • Monomorphic type classes (kind *) use ordinary lambdas to create final instances in a single static factory.
  • Polymorphic type classes (kind * -> *) use Witness types to enable erasure-based factories that work across all A and F[_] instances.
  • Macro-codegen integration: replace new TypeClass[A] { ... } with CatsDerivationFactories.instanceA calls to emit lambdas instead of per-type classes.

Quick Start

Refactor macro code to replace new TypeClass[A] { ... } with CatsDerivationFactories.instanceA calls.

Frequently Asked Questions about kindlings-factory-instance

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

FAQPage Schema
How do I reduce anonymous class emissions in macro typeclass derivations?

Anonymous class emissions in macro typeclass derivations occur when code generation creates a new class per type. Replacing these with reusable factory methods reduces generated class files and speeds up compilation.

How do I refactor macro code to use factory methods for typeclass instances?

Refactor macro code by replacing new TypeClass[A] { ... } emissions with calls to a centralized factory like CatsDerivationFactories.instance[A](...), which generates lambdas instead of per-type anonymous classes.

Can I use factory-based typeclass derivation for polymorphic type classes?

Yes, factory-based derivation supports polymorphic type classes of kind * -> *. It uses Witness types to enable erasure-based factories that work across all A and F[_] instances.

What is the difference between monomorphic and polymorphic factory instances in typeclass derivation?

Monomorphic type classes of kind * use ordinary lambdas to create final instances in a single static factory, while polymorphic type classes of kind * -> * use Witness types for erasure-based factory compatibility.

Does replacing per-type anonymous classes with factory methods improve compilation speed?

Replacing per-type anonymous classes with single reusable factory methods reduces the number of generated .class files. This reduction in runtime footprint speeds up compilation when deriving type classes for many types.

What are the limitations of using factory instances for typeclass derivation?

Factory-based typeclass derivation requires implementing factories in an internal runtime module and updating macro code generation. It relies on erasure-based factories with Witness types for polymorphic support, which may constrain complex type boundaries.