- SyncCollection k v -> SyncCollection k v -> SyncCollection k v -> SyncCollection k v
-findModified basestate state1 lastchildstate =
- Map.mapMaybe id .
- Map.intersectionWithKey comparefunc state1 $ lastchildstate
- where comparefunc k v1 v2 =
- if v1 /= v2
- then case Map.lookup k basestate of
- Nothing -> Nothing
- Just baseval ->
- if baseval == v1
- then Nothing
- else Just v1
- else Nothing
+ SyncCollection k v
+ -> SyncCollection k v
+ -> SyncCollection k v
+ -> SyncCollection k v
+ -> SyncCollection k v
+findModified basestate authoritativestate comparisonstate laststate =
+ Map.mapMaybe id $
+ Map.intersectionWithKey compareFunc comparisonstate laststate
+ where compareFunc k compv lastv =
+ if lastv == compv
+ then Nothing
+ else case (Map.lookup k basestate, Map.lookup k authoritativestate) of
+ (Nothing, _) -> Nothing
+ (Just basev, Nothing) ->
+ if compv /= basev
+ then Just compv
+ else Nothing
+ (Just basev, Just authv) ->
+ if (authv /= lastv) && (authv /= basev)
+ then Just authv
+ else Nothing