The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Tomer Ben David (8) [Avatar] Offline
#1
So the account service looks as following:

trait AccountService[Account, Amount, Balance] { #A
open(no: String, name: String, openDate: Option[Date]): Try[Account]
close(account: Account, closeDate: Option[Date]): Try[Account]
debit(account: Account, amount: Amount): Try[Account]
credit(account: Account, amount: Amount): Try[Account]
balance(account: Account): Try[Balance]
}


so its great it has Try as return type so it can be combined with other operations. So Try is great but it scares me because what if at some point in future I would find out I want this API to be async? I would then need to change it to Future (or to something else). So is there a way out of this? can I have Try or Future or some other combinator that will allow me to have changes in requirements which are unknown today (lets say in future it was unknown that I would need to change the api to async) without chanign the signature of my API?

thanks
Debasish Ghosh (116) [Avatar] Offline
#2
I discuss exactly this topic in chapter 6, section 6.2. Using the power of type system and monad transformers you can achieve this. Feel free to get back if you need more information on this even after reading section 6.2.

Thanks.