Created
March 1, 2015 23:22
-
-
Save guilleiguaran/3781e734e3ae70750e17 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed trait InvoiceStatus | |
case class NoGenerated() extends InvoiceStatus | |
case class Generated() extends InvoiceStatus | |
case class Paid() extends InvoiceStatus | |
case class Invoice[State <: InvoiceStatus](id: Option[Long], value: Long, status: State) | |
trait InvoiceServices { | |
val generate: Invoice[NoGenerated] => Try[Invoice[Generated]] = { | |
c => | |
Try { | |
c.copy(status = Generated()) | |
} | |
} | |
val pay: Invoice[Generated] => Try[Invoice[Paid]] = { | |
c => | |
Try { | |
c.copy(status = Paid()) | |
} | |
} | |
} | |
object InvoiceServices extends InvoiceServices |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment