- commit
- 1703c53
- parent
- 82dee90
- author
- Evgenii Akentev
- date
- 2023-03-30 23:02:46 +0400 +04
[row-handle]: Fix build and use composite implementation for WeatherProvider
2 files changed,
+10,
-5
+2,
-2
1@@ -11,7 +11,7 @@ import qualified WindProvider
2 import qualified TemperatureProvider
3 import QueryTypes
4
5-data WeatherData = WeatherData { temperature :: T.Temperature, wind :: W.WindSpeed }
6+data WeatherData = WeatherData { temperature :: TemperatureProvider.Temperature, wind :: WindProvider.WindSpeed }
7
8 -- We union the methods of providers and extend it with a common method.
9 type Methods = ("getWeatherData" .== (Location -> Day -> IO WeatherData))
10@@ -23,5 +23,5 @@ type Handle = HandleRow Methods
11 getWeatherData :: Handle -> Location -> Day -> IO WeatherData
12 getWeatherData = getMethod @"getWeatherData"
13
14-getWindData :: Handle -> Location -> Day -> IO W.WindSpeed
15+getWindData :: Handle -> Location -> Day -> IO WindProvider.WindSpeed
16 getWindData = getMethod @"getWindData"
1@@ -1,4 +1,6 @@
2+{-# LANGUAGE RecordWildCards #-}
3 {-# LANGUAGE OverloadedLabels #-}
4+
5 module SuperWeatherProvider where
6
7 import Data.Row
8@@ -8,8 +10,11 @@ import qualified WindProvider
9 import QueryTypes
10
11 new :: WindProvider.Handle -> TemperatureProvider.Handle -> Handle
12-new wp tp = #getWeatherData .== getSuperWeatherData .+ wp .+ tp
13+new wp tp = #getWeatherData .== (getSuperWeatherData wp tp) .+ wp .+ tp
14
15 -- | This is some concrete implementation `WeatherProvider` interface
16-getSuperWeatherData :: Location -> Day -> IO WeatherData
17-getSuperWeatherData _ _ = return $ WeatherData 30 10
18+getSuperWeatherData :: WindProvider.Handle -> TemperatureProvider.Handle -> Location -> Day -> IO WeatherData
19+getSuperWeatherData wp tp loc day = do
20+ temperature <- TemperatureProvider.getTemperatureData tp loc day
21+ wind <- WindProvider.getWindData wp loc day
22+ return $ WeatherData{..}