I read the following about coproducts in a great Fearless Guide :
... its value is that Coproducts arent particularly special. The above functionality can be achieved using Either and Nothing instead of: +: and CNil.
Here is the code above:
import shapeless.{Coproduct, :+:, CNil, Inl, Inr}
case class Red()
case class Amber()
case class Green()
type Light = Red :+: Amber :+: Green :+: CNil
val red: Light = Inl(Red())
val green: Light = Inr(Inr(Inl(Green())))
For my own understanding, what is the use, if any, of using Coproduct over sealed trait?
source
share