scala-with-cats
scala-with-cats copied to clipboard
trait
As we said in Essential Scala, there are two functional programming patterns that we should consider when defining a trait:
- we can make it a typeclass, or;
- we can make it an algebraic data type (and hence seal it).
Type classes allow us to unify disparate data types with a common interface. This doesn’t seem like what we’re trying to do here. That leaves us with an algebraic data type. Let’s keep that thought in mind as we explore the design a bit further.