Introduction to code generation with scalameta
summary
Live demo builds a macro that generates a companion with a working toMap/fromMap pair for any case class and the produced code compiles and runs in the example. It uses scalameta and quasiquotes, preserves existing companions, handles type parameters, optional and default fields, and prints generated code for debugging. The author extracted the work into scalameta-serialiser on GitHub, notes partial IDE support and that the approach targets Scala JVM/JS/Native (Android too), and argues scalameta is simpler and more maintainable than old macros.
AI-written summary · about
chapters (8)
- 0:00Start
- 1:47objective for this talk
- 4:06metaprogramming • code that manipulates code
- 8:44feature code generation
- 9:43wiring macro with inline/meta
- 14:52construct and deconstruct ADT using quasiquotes
- 34:43passing values to annotation
- 39:27final thoughts • great metaprogramming DSL
related talks
51mAutomate More Code With Scalameta
21mDeath to boilerplate with Scala meta
01h 37mHands-on Scala.Meta
21mUnlock the Potential of Swift Code Generation
24mCode Generation via Meta-programming in Dependently Typed Proof Assistants
50mMove fast and fix things
01h 19mThe Future of Scala
26mMaking life easier with Derive and other tools
