September 2018
Intermediate to advanced
398 pages
9h 43m
English
Imagine that you implemented a PriceService trait that calls an external website to get the price of a product. You defined its interface as follows:
import cats.data.ValidatedNelcase class Timeout(millis: Int)trait PriceService { def getPrice(productName: String)(implicit timeout: Timeout): ValidatedNel[String, Double]}
The external website might not be responsive, and so our service has to wait a certain amount of time before giving up, indicated by the parameter timeout. As we have seen in Chapter 3, Handling Errors, the service would return Invalid[NonEmptyList[String]] if there were any problem getting the price, or Valid[Double] if we can obtain the price.
In a large application, you could have many more services ...
Read now
Unlock full access