/ShapelesDerivationExample

Demonstration how to use shapeless to derive typeclass instances for sealed trait families.

Primary LanguageScalaGNU General Public License v3.0GPL-3.0

Short example which demonstrates how simply typeclass instance derivation could be done with the help of shapeless.

For this particular example, structural comparison operation derivation is done for sealed trait family.

I.e. for any sealed trait family like:

   sealed trait Color
   
     sealed trait PredefColor extends Color
     case object Red extends PredefColor
     case object Green extends PredefColor
     case object Blue extends PredefColor
   
     case class RGB(r: Int, g: Int, b: Int) extends Color
     case class RGBA(r: Int, g: Int, b: Int, a: Int) extends Color
     case class HSV(h: Int, s: Int, v: Int) extends Color

We derive

val comparer = GenericComparer[Color]

Which allows to determine structural difference between two objects belonging to the same family.

Done by Ivan Kamyshan, 2019.