Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait AccountService {
- def debit(no: String, amount: Amount): Kleisli[Future,AccountRepository, Account] = ???
- def credit(no: String, amount: Amount): ReaderT[Future,AccountRepository, Account] = ???
- def transfer(from: String, to: String, amount: Amount) : ReaderT[Future,AccountRepository, (Account,Account)] = for {
- debitAcc <- debit(from, amount)
- creditAcc <- credit(to, amount)
- } yield (debitAcc, creditAcc) // If you do not use ReaderT/Kleisli here then you need extra mapping to extract accounts from Try
- }
- object AccountService extends AccountService
- object AccountRepository extends AccountRepositoryInMemory
- AccountService.transfer("from", "to", 10).run(AccountRepository)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement