hkj-optics

Generate type-safe lenses, prisms, and traversals for immutable Java records.

78|6|Updated Apr 4, 2025
One-click install
npx skills add https://github.com/higher-kinded-j/higher-kinded-j --skill hkj-optics
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: hkj-optics
Source: https://github.com/higher-kinded-j/higher-kinded-j/tree/main/.claude/skills/hkj-optics
Command: npx skills add https://github.com/higher-kinded-j/higher-kinded-j --skill hkj-optics

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the complexity of navigating and updating deeply nested immutable Java records, eliminating manual boilerplate and error-prone copy-and-set logic.

Core Features & Use Cases

  • Automated Optic Generation: Generates Lenses, Prisms, and Traversals from simple annotations on records and interfaces.
  • Deep Navigation: Provides a fluent Focus DSL to chain paths through nested records, collections, and optional fields.
  • Use Case: Use this to perform complex, type-safe updates on nested domain models, such as updating a specific user's address field within a list of orders, without writing manual copy methods.

Quick Start

Use the hkj-optics skill to generate lenses and focus paths for my User and Address records.

Frequently Asked Questions about hkj-optics

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

FAQPage Schema
How do I update deeply nested immutable Java records without writing manual copy methods?

To update deeply nested immutable Java records without manual copy methods, you use generated optics to perform type-safe, path-based data manipulation. This approach eliminates error-prone copy-and-set logic by enabling fluent deep navigation through complex hierarchies.

What are optics in Java and how do they handle immutable data navigation?

Optics in Java are abstractions like Lenses, Prisms, and Traversals that handle immutable data navigation by composing paths through nested records and collections. They enable targeted updates on specific fields without mutating the original data structure.

How do I generate type-safe lenses for Java record hierarchies?

You generate type-safe lenses for Java record hierarchies by applying simple annotations to your records and interfaces. This annotation-driven code generation automatically creates the necessary optics to satisfy compile-time safety and total immutability requirements.

Can I use optics to update a specific element within a collection of Java records?

Yes, you can use Traversals to update a specific element within a collection of Java records. The generated optics support collection-based data patterns, allowing you to chain focus paths through lists and perform targeted modifications type-safely.

Does annotation-driven code generation for optics work with Java sum types?

Yes, annotation-driven code generation for optics works with Java sum types by generating Prisms. These optics allow you to safely navigate and manipulate variant-specific data within your hierarchical domain models during compilation.

What is the best way to navigate complex nested domain models in Java immutably?

The best way to navigate complex nested domain models immutably is using a fluent Focus DSL to chain paths through nested records, collections, and optional fields. This provides expressive, type-safe data manipulation without manual boilerplate.