/SmartConstructors

Minimal project to show Smart Constructor Pattern with Scala

Primary LanguageScalaApache License 2.0Apache-2.0

Minimal project to show Smart Constructor Pattern with Scala

See a thorough discussion of the Smart Constructor Pattern here

This project uses two implementations for the Smart Constructor pattern in Scala.

  1. The weird (but useful)
sealed abstract case class Foo()

Rob Norris (@tpolecat in github, twitter), a very well known typelevel contributor, explains it very nicely in this gist. This approach has the benefit that does not require compiler plugins.

  1. Using the @data annotation (requires scala macros)
@data(copy=false, apply=false) 
class Foo()

Additional Information/Links