SyncCommand k v =
DeleteItem k
| CopyItem k v
- | ModifyContent k v
+ | SetContent k v
deriving (Eq, Ord, Show)
pairToFunc :: (a -> b -> c) -> (a, b) -> c
++
(map (pairToFunc CopyItem) .
findAdded childstate masterstate $ lastchildstate)
- ++ (map (pairToFunc ModifyContent) . Map.toList $ masterPayloadChanges)
+ ++ (map (pairToFunc SetContent) . Map.toList $ masterPayloadChanges)
childchanges = (map DeleteItem .
findDeleted masterstate childstate $ lastchildstate)
++
(map (pairToFunc CopyItem) .
findAdded masterstate childstate $ lastchildstate)
- ++ (map (pairToFunc ModifyContent) . Map.toList $ childPayloadChanges)
+ ++ (map (pairToFunc SetContent) . Map.toList $ childPayloadChanges)
masterPayloadChanges =
Map.union
(findModified masterstate childstate childstate lastchildstate)
(map (pairToFunc CopyItem) . findAdded coll2 coll1 $ coll1) ++
modifiedData
where modifiedData =
- map (pairToFunc ModifyContent) .
+ map (pairToFunc SetContent) .
Map.toList .
Map.mapMaybe id .
Map.intersectionWith compareFunc coll1 $ coll2
{-
- (map (pairToFunc ModifyContent) . Map.toList .
+ (map (pairToFunc SetContent) . Map.toList .
findModified coll1 coll2 $ coll1)
-}
Map.delete key collection
makeChange collection (CopyItem key val) =
Map.insert key val collection
- makeChange collection (ModifyContent key val) =
+ makeChange collection (SetContent key val) =
Map.adjust (\_ -> val) key collection
in foldl makeChange collection commands
-{- | Given the base input and a ModifyContent command, convert this to
-commands to sync. Ignores anything that is not a ModifyContent command
+{- | Given the base input and a SetContent command, convert this to
+commands to sync. Ignores anything that is not a SetContent command
by returning an empty list. -}
modifyToSync :: (Eq k, Ord k, Show k, Eq v, Show v, Eq v', Show v', Ord v) =>
SyncCollection k (SyncCollection v v')
-> SyncCommand k (SyncCollection v v')
-> [SyncCommand v v']
-modifyToSync base (ModifyContent key val) =
+modifyToSync base (SetContent key val) =
case Map.lookup key base of
Nothing -> error $ "modifyToSync: attempt to modify on unknown base key " ++ show key
Just basev ->
expectedResChild = sort $
(map (\(k, v) -> CopyItem k v) . Map.toList . Map.difference master $ child) ++
(map DeleteItem . Map.keys . Map.difference child $ master) ++
- (map (pairToFunc ModifyContent) changeList)
+ (map (pairToFunc SetContent) changeList)
changeList = foldl changefunc [] (Map.toList child)
changefunc accum (k, v) =
case Map.lookup k master of
expectedResMaster = sort $
(map (pairToFunc CopyItem) . Map.toList . Map.difference child $ master) ++
(map DeleteItem . Map.keys . Map.difference master $ child) ++
- (map (pairToFunc ModifyContent) changeList)
+ (map (pairToFunc SetContent) changeList)
changeList = foldl changefunc [] (Map.toList child)
changefunc accum (k, v) =
case Map.lookup k master of
expectedResMaster = sort $
(map (pairToFunc CopyItem) . Map.toList . Map.difference child $ Map.union master lastchild) ++
(map DeleteItem . Map.keys . Map.intersection master $ Map.difference lastchild child) ++
- (map (pairToFunc ModifyContent) masterMods)
+ (map (pairToFunc SetContent) masterMods)
expectedResChild = sort $
(map (pairToFunc CopyItem) . Map.toList . Map.difference master $ Map.union child lastchild) ++
(map DeleteItem . Map.keys . Map.intersection child $ Map.difference lastchild master) ++
- (map (pairToFunc ModifyContent) childMods)
+ (map (pairToFunc SetContent) childMods)
in (expectedResMaster, expectedResChild) @=?
(sort resMaster, sort resChild)