title: Scala: the verification of correctness code example not working
body: <p>I am reading now <code>Functional and Reactive Domain Modeling</code>. In the section 1.5, pg 30, there is an example:</p>
  
  <pre><code>credit(a, 100).flatMap(debit(_, 100))
  =&gt; Success(a.copy(balance = Balance(0 + 100))).flatMap(debit(_, 100))
  =&gt; debit(Account("a1", "John", .., Balance(100)), 100)
  =&gt; Success(a.copy(balance = Balance(100 - 100)))
  =&gt; Success(Account("a1", "John", .., Balance(0)))
  </code></pre>
  
  <p>I understand in general, what we do here: we substitute the functions with its implementations, for both <code>credit</code> and <code>debit</code> operations. In order to get finally the original result. But the exact example does not work. </p>
  
  <p>For instance, with unit tests we use assertion to make sure it works. And as a result, to verify code, I can write expression and compare it. Here   is a strange syntax. What does "=>" mean? There is no any comparison. How would you verify the correctness </p>
  
  <p>Here is a full example of the code before this verification to be able to run it:</p>
  
  <pre><code>import java.util.{ Date, Calendar }
  import scala.util.{ Try, Success, Failure }
  def today = Calendar.getInstance.getTime
  type Amount = BigDecimal
  case class Balance(amount: Amount = 0)
  case class Account(no: String, name: String,
    dateOfOpening: Date, balance: Balance = Balance())
  
  trait AccountService {
    def debit(a: Account, amount: Amount): Try[Account] = {
      if (a.balance.amount &lt; amount)
        Failure(new Exception("Insufficient balance in account"))
      else Success(a.copy(balance = Balance(a.balance.amount – amount)))
    }
    def credit(a: Account, amount: Amount): Try[Account] =
      Success(a.copy(balance = Balance(a.balance.amount + amount)))
  }
  
  object AccountService extends AccountService
  import AccountService._
  
  val t = today
  val a = Account("a1", "John", t)
  </code></pre>