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.
YOU MAY ALSO LIKE:
- Shapeless is Dead! Long Live Shapeless! (SkillsCast recorded in December 2017)
- ScalaCon 2021 (Online Conference on 18th - 22nd May 2021)
- An Introduction to Cats Effect with Adam Rosien (SkillsCast recorded in April 2021)
- Abstract Data Types In The Region Of Abysmal Pain, And How To Navigate Them (SkillsCast recorded in September 2019)
Case classes a la carte with shapeless, now!
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.