Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@debasishg
Created April 27, 2015 20:48
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 debasishg/5d6869b10c0d8c514c6a to your computer and use it in GitHub Desktop.
Save debasishg/5d6869b10c0d8c514c6a to your computer and use it in GitHub Desktop.
Welcome to Scala version 2.11.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_65).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import frdomain.ch3.repository._
import frdomain.ch3.repository._
scala> import reader._
import reader._
scala> val a = Account("a-123", "abc")
a: frdomain.ch3.repository.Account = Account(a-123,abc,Tue Apr 28 02:14:04 GMT+05:30 2015,None,Balance(0))
scala> val s = AccountRepositoryInMemory
s: frdomain.ch3.repository.AccountRepositoryInMemory.type = frdomain.ch3.repository.AccountRepositoryInMemory$@705b0bc4
scala> s.store(a)
res0: scala.util.Try[frdomain.ch3.repository.Account] = Success(Account(a-123,abc,Tue Apr 28 02:14:04 GMT+05:30 2015,None,Balance(0)))
scala> import AccountService._
import AccountService._
scala> object App {
| def op(no: String) = for {
| _ <- credit(no, BigDecimal(100))
| _ <- credit(no, BigDecimal(300))
| _ <- debit(no, BigDecimal(160))
| b <- balance(no)
| } yield b
| }
defined object App
scala> import App._
import App._
scala> op("a-123") run s
res2: scala.util.Try[frdomain.ch3.repository.Balance] = Success(Balance(240))
scala> op("a-143") run s
res3: scala.util.Try[frdomain.ch3.repository.Balance] = Failure(java.lang.Exception: No account exists with no a-143)
scala>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment