Advertisement
Guest User

Untitled

a guest
Jan 21st, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. trait AccountService {
  2.  
  3. type Valid[A] = OptionT[Future, A]
  4. type AccountOperation[A] = Kleisli[Valid, AccountRepository, A]
  5.  
  6. def debit(no: String, amount: Amount): AccountOperation[Account] = ???
  7. def credit(no: String, amount: Amount): AccountOperation[Account] = ???
  8. def transfer(from: String, to: String, amount: Amount) : AccountOperation[(Account,Account)] = for {
  9. debitAcc <- debit(from, amount)
  10. creditAcc <- credit(to, amount)
  11. } yield (debitAcc, creditAcc) // You need OptionT transformer inside Kleisli/ReaderT to avoid extra mapping to extract account from stacked Future[Option] monads.
  12. }
  13.  
  14. object AccountService extends AccountService
  15.  
  16. object AccountRepository extends AccountRepositoryInMemory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement