Derive type classes for ADTs using `derives`
mainShapeless 3 provides a generalized implementation of type class derivation. You can use the derives keyword on case classes or enums to automatically generate instances for type classes.
Supported kinds include:
*(e.g.,Monoid,Eq,Show)* -> *(e.g.,Functor,Traverse,Monad)(* -> *) -> *(e.g.,FunctorK/HFunctor)* -> * -> *(e.g.,Bifunctor)
This approach is more efficient in terms of compile-time and runtime performance, and results in a smaller binary footprint compared to Shapeless 2.
import shapeless3.deriving.*
// Example: Deriving a Monoid for a case class
trait Monoid[A]:
def empty: A
def combine(x: A, y: A): A
// ... (Monoid implementation details) ...
case class ISB(i: Int, s: String, b: Boolean) derives Monoid
val a = ISB(23, "foo", true)
val b = ISB(13, "bar", false)
val c = a |+| b // == ISB(36, "foobar", true)