Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. trait AccountService {
  2. def debit(no: String, amount: Amount): Kleisli[Future,AccountRepository, Account] = ???
  3. def credit(no: String, amount: Amount): ReaderT[Future,AccountRepository, Account] = ???
  4. def transfer(from: String, to: String, amount: Amount) : ReaderT[Future,AccountRepository, (Account,Account)] = for {
  5. debitAcc <- debit(from, amount)
  6. creditAcc <- credit(to, amount)
  7. } yield (debitAcc, creditAcc) // If you do not use ReaderT/Kleisli here then you need extra mapping to extract accounts from Try
  8. }
  9.  
  10. object AccountService extends AccountService
  11.  
  12. object AccountRepository extends AccountRepositoryInMemory
  13.  
  14. AccountService.transfer("from", "to", 10).run(AccountRepository)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement