Part 1. The Immutability Gap: Why Java Records Need Optics
Part 2. Optics: Lenses, Prisms, and Traversals in Practice
Useful links:
JEP 468. Derived Record Creation
Runnable Demos on GitHub.
Optics Fundamentals
┌─────────┐
│ Fold │ (read-only, zero-or-more)
└────┬────┘
│
┌──────────┴──────────┐
│ │
┌────┴────┐ ┌─────┴─────┐
│ Getter │ │ Traversal │ (read-write, zero-or-more)
└────┬────┘ └─────┬─────┘
│ │
│ ┌─────┴─────┐
│ │ │
┌────┴────┐ ┌─────┴─────┐ ┌───┴───┐
│ Lens │ │ Affine │ │Setter │
└────┬────┘ └─────┬─────┘ └───────┘
│ (zero-or-one)
│ │
│ ┌─────┴─────┐
│ │ Prism │
│ └─────┬─────┘
│ │
└───────┬───────┘
┌────┴────┐
│ Iso │ (exactly-one, reversible)
└─────────┘