src/main/scala/BankAccount.scala

1
2
3
4
5
6
7
8
9
10
11
12
case class BankAccount() {
  private var balance: Option[Int] = Some(0)

  def getBalance = balance
  def incrementBalance(by: Int) = {
    this.synchronized {
      balance = balance.map { _ + by }
    }
    balance
  }
  def closeAccount() { balance = None }
}

@abo64 thinks this looks great

Comments


You're not logged in right now. Please login via GitHub to comment