[row-handle]: add examples of row types master
authorEvgenii Akentev <i@ak3n.com>
Fri, 31 Mar 2023 20:27:33 +0000 (00:27 +0400)
committerEvgenii Akentev <i@ak3n.com>
Fri, 31 Mar 2023 20:27:33 +0000 (00:27 +0400)
row-handle/domain/WeatherProvider.hs

index 2a18204a320b8acac1ddfa1b3c2b86205a91d139..0194e9a02a2f968ee69692400e896550fd302f7b 100644 (file)
@@ -25,3 +25,29 @@ getWeatherData = getMethod @"getWeatherData"
 
 getWindData :: Handle -> Location -> Day -> IO WindProvider.WindSpeed
 getWindData = getMethod @"getWindData"
+
+-- Some examples of what else is possible with row types.
+
+-- We can remove an item from the record
+type WindAndTemperatureMethods = Methods .- "getWeatherData"
+
+test1 :: Rec WindAndTemperatureMethods -> Rec (WindProvider.Methods .+ TemperatureProvider.Methods)
+test1 = id
+
+-- It's possible to override methods
+type MethodsWithUpdatedWeatherData = ("getWeatherData" .== (Location -> Day -> IO Int)) .// Methods
+
+test2 :: Rec MethodsWithUpdatedWeatherData -> Rec (("getWeatherData" .== (Location -> Day -> IO Int)) .+ WindProvider.Methods .+ TemperatureProvider.Methods)
+test2 = id
+
+-- And to remove them by taking a row difference
+type MethodsWithoutWeatherData = Methods .\\ ("getWeatherData" .== (Location -> Day -> IO WeatherData))
+
+test3 :: Rec MethodsWithoutWeatherData -> Rec WindAndTemperatureMethods
+test3 = id
+
+-- The minimum join of the two rows.
+type JoinedMethods = Methods .\/ Methods
+
+test4 :: Rec JoinedMethods -> Rec Methods
+test4 = id
\ No newline at end of file