Magnolia: Generic Derivation 2.0
summary
Magnolia is a ~400-line Apache-2 macro that generates typeclass instances for case classes, sealed traits, case objects, value classes and tuples, with special support for recursive ADTs and implicit prioritization. It deduplicates generated code and caches implicit searches so compilation can be much faster — one example shows 2 seconds vs ~50 seconds for a large ADT; worst-case measured speedups reach 4x and a microbenchmark gave 52x when creating a million instances. It also produces better error traces when derivation fails.
AI-written summary · about
chapters (7)
- 0:00Introduction
- 0:49What is generic derivation
- 5:48What is Magnolia
- 9:51Type class
- 14:57Contravariant types
- 19:01Compiler performance
- 21:20Lifted case parameters
related talks
01h 12mDeriving pleasure
34mMaterialize Typeclasses with Magnolia
42mAvoiding macros with inline and derived
29mADVENTURES IN META-PROGRAMMING
20mMagnum: A "New Look" for Scala 3 Database Clients
40mMacros vs Types
43mAdventures in Metaprogramming: Macros versus Shapeless
33mMonocle 3: a peek into the future
