From 5403ccb38f767ca258e99e4891b3acadf6876da0 Mon Sep 17 00:00:00 2001 From: Evgenii Akentev Date: Sat, 9 Jan 2021 18:42:07 +0500 Subject: [PATCH] [vinyl-handle]: hide implementation details --- vinyl-handle/domain/WeatherProvider.hs | 9 +++++++++ vinyl-handle/domain/WeatherReporter.hs | 5 +---- vinyl-handle/impl/SuperWeatherProvider.hs | 12 ++++++------ vinyl-handle/test-impl/TestWeatherProvider.hs | 12 ++++++------ 4 files changed, 22 insertions(+), 16 deletions(-) diff --git a/vinyl-handle/domain/WeatherProvider.hs b/vinyl-handle/domain/WeatherProvider.hs index 360861c..90da696 100644 --- a/vinyl-handle/domain/WeatherProvider.hs +++ b/vinyl-handle/domain/WeatherProvider.hs @@ -1,6 +1,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TypeApplications #-} module WeatherProvider where @@ -18,3 +19,11 @@ type Methods = '[ '("getWeatherData", (Location -> Day -> IO WeatherData)) type Handle = HandleRec Methods +getWeatherData :: Handle -> Location -> Day -> IO WeatherData +getWeatherData = getMethod @"getWeatherData" + +getTemperatureData :: Handle -> Location -> Day -> IO T.Temperature +getTemperatureData = getMethod @"getTemperatureData" + +getWindData :: Handle -> Location -> Day -> IO W.WindSpeed +getWindData = getMethod @"getWindData" diff --git a/vinyl-handle/domain/WeatherReporter.hs b/vinyl-handle/domain/WeatherReporter.hs index 31a0916..b5aec33 100644 --- a/vinyl-handle/domain/WeatherReporter.hs +++ b/vinyl-handle/domain/WeatherReporter.hs @@ -4,9 +4,6 @@ module WeatherReporter where -import HandleRec -import Data.Vinyl as V - import qualified WeatherProvider type WeatherReport = String @@ -27,5 +24,5 @@ createWeatherReport (WeatherProvider.WeatherData temp wind) = -- | Domain logic that uses external dependency to get data and process it. getCurrentWeatherReportInLondon :: Handle -> IO WeatherReport getCurrentWeatherReportInLondon (Handle wph) = do - weatherData <- (getMethod @"getWeatherData" wph) "London" "now" + weatherData <- WeatherProvider.getWeatherData wph "London" "now" return $ createWeatherReport weatherData diff --git a/vinyl-handle/impl/SuperWeatherProvider.hs b/vinyl-handle/impl/SuperWeatherProvider.hs index ea2b575..885976d 100644 --- a/vinyl-handle/impl/SuperWeatherProvider.hs +++ b/vinyl-handle/impl/SuperWeatherProvider.hs @@ -8,16 +8,16 @@ import QueryTypes new :: Handle new = Field getSuperWeatherData - :& Field getWindData - :& Field getTemperatureData + :& Field getSuperWindData + :& Field getSuperTemperatureData :& RNil -- | This is some concrete implementation `WeatherProvider` interface getSuperWeatherData :: Location -> Day -> IO WeatherData getSuperWeatherData _ _ = return $ WeatherData 30 10 -getTemperatureData :: Location -> Day -> IO Temperature -getTemperatureData _ _ = return 30 +getSuperTemperatureData :: Location -> Day -> IO Temperature +getSuperTemperatureData _ _ = return 30 -getWindData :: Location -> Day -> IO WindSpeed -getWindData _ _ = return 5 +getSuperWindData :: Location -> Day -> IO WindSpeed +getSuperWindData _ _ = return 5 diff --git a/vinyl-handle/test-impl/TestWeatherProvider.hs b/vinyl-handle/test-impl/TestWeatherProvider.hs index f5ae089..5d576c6 100644 --- a/vinyl-handle/test-impl/TestWeatherProvider.hs +++ b/vinyl-handle/test-impl/TestWeatherProvider.hs @@ -14,8 +14,8 @@ data Config = Config new :: Config -> Handle new config = Field (getTestWeatherData (initTemperature config) (initWindSpeed config)) - :& Field (getWindData (initWindSpeed config)) - :& Field (getTemperatureData (initTemperature config)) + :& Field (getTestWindData (initWindSpeed config)) + :& Field (getTestTemperatureData (initTemperature config)) :& RNil -- | This is an implementation `WeatherProvider` interface for tests @@ -23,8 +23,8 @@ new config = Field (getTestWeatherData (initTemperature config) (initWindSpeed c getTestWeatherData :: T.Temperature -> W.WindSpeed -> Location -> Day -> IO WeatherData getTestWeatherData temp wind _ _ = return $ WeatherData temp wind -getTemperatureData :: T.Temperature -> Location -> Day -> IO T.Temperature -getTemperatureData t _ _ = return t +getTestTemperatureData :: T.Temperature -> Location -> Day -> IO T.Temperature +getTestTemperatureData t _ _ = return t -getWindData :: W.WindSpeed -> Location -> Day -> IO W.WindSpeed -getWindData w _ _ = return w +getTestWindData :: W.WindSpeed -> Location -> Day -> IO W.WindSpeed +getTestWindData w _ _ = return w -- 2.34.1