New types as solution to primitive obsession
summary
Compares concrete implementations for eliminating primitive-obsession: value classes, opaque types, and tagged types, plus libraries Monix Newtypes, kebs/caps, ZIO Prelude, refined and Mazboot. Shows working examples (Person and Book) with per-field types, validates ISBN checksum and nonblank titles, composes validated fields with for-comprehensions, and explains where validation runs (compile-time assertions in ZIO vs runtime checks in Monix/caps). Notes Scala 2 vs Scala 3 availability, codec/serialization gaps, and that Monix is zero-dependency while ZIO Prelude brings ZIO into the dependency graph.
AI-written summary · about
chapters (21)
- 0:00Introduction to primitive obsession
- 1:05Defining the problem with primitives
- 2:57Pure Scala solutions overview
- 5:28Target types approach
- 6:33Opaque types approach
- 7:59Libraries for new types
- 8:22Monix new types library
- 9:47Demo with Monix new types
- 11:57Monix pros and cons
- 12:39ZIO Prelude library
- 15:15Demo with ZIO Prelude
- 16:41ZIO Prelude pros and cons
- 17:44Caps Opaque library
- 18:47Demo with Caps Opaque
- 19:52Caps Opaque pros and cons
- 20:13Caps Duct for Scala 2
- 21:20Demo with Caps Duct
- 22:52Caps Duct pros and cons
- 25:02Other libraries overview
- 26:33Final conclusions and recommendations
- 28:39Q&A and resources
