[vinyl-handle]: hide implementation details
authorEvgenii Akentev <i@ak3n.com>
Sat, 9 Jan 2021 13:42:07 +0000 (18:42 +0500)
committerEvgenii Akentev <i@ak3n.com>
Sat, 9 Jan 2021 13:42:07 +0000 (18:42 +0500)
vinyl-handle/domain/WeatherProvider.hs
vinyl-handle/domain/WeatherReporter.hs
vinyl-handle/impl/SuperWeatherProvider.hs
vinyl-handle/test-impl/TestWeatherProvider.hs

index 360861ca8f20d0042af21bf4b0c4480c21785e80..90da6964240c31e4673daa47307c26e388f36350 100644 (file)
@@ -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"
index 31a091667b42134050c1b2bb481db80b214a0439..b5aec33080418188520c444135f7133254bbcc12 100644 (file)
@@ -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
index ea2b5753c9d28d6ad06159b13b9f3ea9941d444b..885976d16fc3e36ddda12f1871aae3553ec9caf2 100644 (file)
@@ -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
index f5ae0891386941ff8a38519bd7692996be0397e1..5d576c6815843b8e66c6fb196f4e915cc7781f50 100644 (file)
@@ -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