Advertisement
Guest User

Untitled

a guest
Jan 9th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.21 KB | None | 0 0
  1. package taglessfinal
  2.  
  3. import external.GoogleLocation
  4.  
  5. import scala.concurrent.Future
  6.  
  7. /**
  8.   * @author Alexander Isakov
  9.   */
  10. trait GoogleLocationService[F[_]] {
  11.  
  12.   def getByAddress(address: String): F[GoogleLocation]
  13.  
  14. }
  15.  
  16. sealed trait GoogleLocationServiceError
  17. case object ConnectionError             extends GoogleLocationServiceError
  18. case object GoogleLocationNotFoundError extends GoogleLocationServiceError
  19.  
  20. object GoogleLocationService {
  21.  
  22.   type DefaultResult[A] = Future[Either[GoogleLocationServiceError, A]]
  23.  
  24.   val defaultGoogleLocationService = new GoogleLocationService[DefaultResult] {
  25.     def getByAddress(address: String): DefaultResult[GoogleLocation] = ???
  26.   }
  27.  
  28.   //
  29.  
  30.   type LocationServiceResult[A] = Future[Either[LocationError, A]]
  31.  
  32.   val defaultGoogleLocationServiceForLocationService = new GoogleLocationService[LocationServiceResult] {
  33.     def getByAddress(address: String): LocationServiceResult[GoogleLocation] = {
  34.       defaultGoogleLocationService
  35.         .getByAddress(address)
  36.         .map(_.left.map {
  37.           case ConnectionError             => RetryLaterError
  38.           case GoogleLocationNotFoundError => InvalidLocationArgumentsError
  39.         })
  40.     }
  41.   }
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement