calvinlfer / account-experiment

1 stars 1 forks source link

Tagless Final #1

Open calvinlfer opened 6 years ago

calvinlfer commented 6 years ago

Mention that instead of imposing a Monad implementation at the trait/class level, you can actually do it at the function level. So

// import flatMap/Monad syntax 
def capture(amount: Money)(implicit m: Monad[Effect]): Account => Effect[Account] = account =>
  for {
    accWithMoney <- cancel(amount)(account)       // remove the hold
    accResult    <- debit(amount)(accWithMoney)   // debit the account
  } yield accResult
calvinlfer commented 6 years ago

This allows us to be surgical and precise and not require a Monad implementation to use cancel and debit which do not need it

calvinlfer commented 6 years ago

Return type can also be a Klesili[Effect, Account, Account]