Sha256: a1e9d7830ca73a0d57dc5b9ee61256ad7b366efeefe8927df45492e3454bbe18
Contents?: true
Size: 675 Bytes
Versions: 26
Compression:
Stored size: 675 Bytes
Contents
trait BankAccount { def closeAccount(): Unit def getBalance: Option[Int] def incrementBalance(increment: Int): Option[Int] } protected case class Account(var balance: Option[Int] = Some(0)) extends BankAccount { private def runThreadSafe[A](block: => A): A = this.synchronized(block) override def closeAccount(): Unit = runThreadSafe(balance = None) override def getBalance: Option[Int] = runThreadSafe(balance) override def incrementBalance(increment: Int): Option[Int] = runThreadSafe { balance flatMap { amount => balance = Some(amount + increment) balance } } } object BankAccount { def apply(): BankAccount = Account() }
Version data entries
26 entries across 26 versions & 1 rubygems