Skip to content

Instantly share code, notes, and snippets.

@justinhj
Last active January 4, 2020 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinhj/f1f09691dd12806ebe9eebea8a8a5c40 to your computer and use it in GitHub Desktop.
Save justinhj/f1f09691dd12806ebe9eebea8a8a5c40 to your computer and use it in GitHub Desktop.
case class AccountState(balance: Int, accountHolder: LastOption[String])
object AccountState {
implicit def accountStateShow[A] = new Show[AccountState] {
def show(a: AccountState): String = {
show"Balance: ${a.balance}\nAccount holder: ${a.accountHolder}"
}
}
implicit val accountMonoid = new Monoid[AccountState] {
def empty : AccountState = AccountState(0, None)
def combine(p1: AccountState, p2: AccountState) : AccountState = {
AccountState(p1.balance |+| p2.balance, p1.accountHolder |+| p2.accountHolder)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment