From: Evgenii Akentev Date: Thu, 30 Mar 2023 19:02:46 +0000 (+0400) Subject: [row-handle]: Fix build and use composite implementation for WeatherProvider X-Git-Url: https://git.ak3n.com/?a=commitdiff_plain;h=1703c53cb248dff24ce87d43fae7a4de39e2ea45;p=handle-examples.git [row-handle]: Fix build and use composite implementation for WeatherProvider --- diff --git a/row-handle/domain/WeatherProvider.hs b/row-handle/domain/WeatherProvider.hs index a767a0c..2a18204 100644 --- a/row-handle/domain/WeatherProvider.hs +++ b/row-handle/domain/WeatherProvider.hs @@ -11,7 +11,7 @@ import qualified WindProvider import qualified TemperatureProvider import QueryTypes -data WeatherData = WeatherData { temperature :: T.Temperature, wind :: W.WindSpeed } +data WeatherData = WeatherData { temperature :: TemperatureProvider.Temperature, wind :: WindProvider.WindSpeed } -- We union the methods of providers and extend it with a common method. type Methods = ("getWeatherData" .== (Location -> Day -> IO WeatherData)) @@ -23,5 +23,5 @@ type Handle = HandleRow Methods getWeatherData :: Handle -> Location -> Day -> IO WeatherData getWeatherData = getMethod @"getWeatherData" -getWindData :: Handle -> Location -> Day -> IO W.WindSpeed +getWindData :: Handle -> Location -> Day -> IO WindProvider.WindSpeed getWindData = getMethod @"getWindData" diff --git a/row-handle/impl/SuperWeatherProvider.hs b/row-handle/impl/SuperWeatherProvider.hs index 3a110f2..7b9c650 100644 --- a/row-handle/impl/SuperWeatherProvider.hs +++ b/row-handle/impl/SuperWeatherProvider.hs @@ -1,4 +1,6 @@ +{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE OverloadedLabels #-} + module SuperWeatherProvider where import Data.Row @@ -8,8 +10,11 @@ import qualified WindProvider import QueryTypes new :: WindProvider.Handle -> TemperatureProvider.Handle -> Handle -new wp tp = #getWeatherData .== getSuperWeatherData .+ wp .+ tp +new wp tp = #getWeatherData .== (getSuperWeatherData wp tp) .+ wp .+ tp -- | This is some concrete implementation `WeatherProvider` interface -getSuperWeatherData :: Location -> Day -> IO WeatherData -getSuperWeatherData _ _ = return $ WeatherData 30 10 +getSuperWeatherData :: WindProvider.Handle -> TemperatureProvider.Handle -> Location -> Day -> IO WeatherData +getSuperWeatherData wp tp loc day = do + temperature <- TemperatureProvider.getTemperatureData tp loc day + wind <- WindProvider.getWindData wp loc day + return $ WeatherData{..}