Skip to content

Instantly share code, notes, and snippets.

@priort

priort/JazzBandsDomain3.scala Secret

Created Dec 30, 2018
Embed
What would you like to do?
object Domain {
sealed trait JazzBand
final case class PianoTrio(pianoPlayer: PianoPlayer,
bassPlayer: BassPlayer,
drummer: Drummer) extends JazzBand
final case class Quintet(saxPlayer: SaxPlayer,
trumpetPlayer: TrumpetPlayer,
pianoPlayer: PianoPlayer,
bassPlayer: BassPlayer,
drummer: Drummer) extends JazzBand
final case class Quartet(trumpetPlayer: TrumpetPlayer,
pianoPlayer: PianoPlayer,
bassPlayer: BassPlayer,
drummer: Drummer) extends JazzBand
case class TrumpetPlayer private(name: String) {
def copy() = TrumpetPlayer(name: String)
}
object TrumpetPlayer {
def apply(name: String): Option[TrumpetPlayer] =
List("Miles Davis", "Freddie Hubbard").find(_ == name).map(new TrumpetPlayer(_))
}
case class SaxPlayer private(name: String) {
def copy() = SaxPlayer(name: String)
}
object SaxPlayer {
def apply(name: String): Option[SaxPlayer] =
List("John Coltrane", "Charile Parker").find(_ == name).map(new SaxPlayer(_))
}
case class PianoPlayer private(name: String) {
def copy() = PianoPlayer(name: String)
}
object PianoPlayer {
def apply(name: String): Option[PianoPlayer] =
List("Bill Evans", "Herbie Hancock").find(_ == name).map(new PianoPlayer(_))
}
case class BassPlayer private(name: String) {
def copy() = BassPlayer(name)
}
object BassPlayer {
def apply(name: String): Option[BassPlayer] =
List("Paul Chambers", "Dave Holland").find(_ == name).map(new BassPlayer(_))
}
case class Drummer private(name: String) {
def copy() = Drummer(name)
}
object Drummer {
def apply(name: String): Option[Drummer] =
List("Max Roache", "Tony Williams", "Elvin Jones").find(_ == name).map(new Drummer(_))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.