Skip to content

Instantly share code, notes, and snippets.

@guilleiguaran
Created March 1, 2015 23:22
Show Gist options
  • Save guilleiguaran/3781e734e3ae70750e17 to your computer and use it in GitHub Desktop.
Save guilleiguaran/3781e734e3ae70750e17 to your computer and use it in GitHub Desktop.
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