repos / handle-examples.hs.git


handle-examples.hs.git / vinyl-handle / domain
Evgenii Akentev  ·  2021-01-09

WeatherReporter.hs

 1{-# LANGUAGE TypeApplications #-}
 2{-# LANGUAGE OverloadedStrings #-}
 3{-# LANGUAGE DataKinds #-}
 4
 5module WeatherReporter where
 6
 7import qualified WeatherProvider
 8
 9type WeatherReport = String
10
11-- | We hide dependencies in the handle
12data Handle = Handle { weatherProvider :: WeatherProvider.Handle }
13
14-- | Constructor for Handle
15new :: WeatherProvider.Handle -> Handle
16new = Handle
17
18-- | Domain logic. Usually some pure code that might use mtl, free monads, etc.
19createWeatherReport :: WeatherProvider.WeatherData -> WeatherReport
20createWeatherReport (WeatherProvider.WeatherData temp wind) =
21  "The current temperature in London is " ++ (show temp)
22  ++ " and wind speed is " ++ (show wind)
23
24-- | Domain logic that uses external dependency to get data and process it.
25getCurrentWeatherReportInLondon :: Handle -> IO WeatherReport
26getCurrentWeatherReportInLondon (Handle wph) = do
27  weatherData <- WeatherProvider.getWeatherData wph "London" "now"
28  return $ createWeatherReport weatherData