Please log in to watch this conference skillscast.
But not everything is rosy. Case classes come with restrictions, some of which are essential, some not. And they have some characteristics, again some essential, some not, which are not always entirely appropriate or desirable. This has led to the often expressed desire to be able to pick and choose or otherwise customize case class features: case classes a la carte.
Unfortunately this has seemed to require changes to the Scala compiler which for various reasons have been perceived to be too difficult or too risky to attempt. The arrival of macros, macro annotations in particular, briefly raised the prospect that case classes a la carte might again be on the table. But macro annotations are not yet available in a production ready Scala compiler and might never be.
But all is not lost. Generating the scaffolding for case classes is a generic programming problem, and the fact that one solution to that problem is hard coded into scalac doesn't preclude other approaches from being applied. To that end I will demonstrate one way of tackling this problem using the generic programming library shapeless, and show some of the exciting new possibilities this opens up ... crucially in the context of current (ie. 2.10.x and 2.11.x) Scala compilers.
https://github.com/milessabin/shapeless
YOU MAY ALSO LIKE:
- Shapeless is Dead! Long Live Shapeless! (SkillsCast recorded in December 2017)
- ScalaCon 2022: Opening Keynote Networking Party (in London on 4th October 2022)
- ScalaCon 2022 (Online Conference on 4th - 8th October 2022)
- TDD and other drugs (Online Meetup on 8th August 2022)
- LJC: I Started Testing In Production... Then I Went On Holiday (Online Meetup on 15th August 2022)
- A History of Enterprise Monads (SkillsCast recorded in May 2021)
- Connecting the dots - building and structuring a functional application in Scala (SkillsCast recorded in May 2021)
Case classes a la carte with shapeless, now!
Miles Sabin
Miles has been doing stuff with Scala for more than ten years, currently with Underscore Consulting. He is a cofounder of Typelevel and his best known project, the Scala generic programming library shapeless, is the weapon of choice wherever boilerplate needs to be scrapped or arities abstracted over.