Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait AccountService {
- type Valid[A] = OptionT[Future, A]
- type AccountOperation[A] = Kleisli[Valid, AccountRepository, A]
- def debit(no: String, amount: Amount): AccountOperation[Account] = ???
- def credit(no: String, amount: Amount): AccountOperation[Account] = ???
- def transfer(from: String, to: String, amount: Amount) : AccountOperation[(Account,Account)] = for {
- debitAcc <- debit(from, amount)
- creditAcc <- credit(to, amount)
- } yield (debitAcc, creditAcc) // You need OptionT transformer inside Kleisli/ReaderT to avoid extra mapping to extract account from stacked Future[Option] monads.
- }
- object AccountService extends AccountService
- object AccountRepository extends AccountRepositoryInMemory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement