]> code.delx.au - offlineimap/blobdiff - src/Data/Syncable.hs
Adding new unaryApplyChanges test
[offlineimap] / src / Data / Syncable.hs
index d9226c41d964b9b59b51462e78a82876ae667888..aa03932bc9ec0b500ccf12bf5eb12efcff47da40 100644 (file)
@@ -117,3 +117,16 @@ filterKeys state keylist =
               case Map.lookup k state of
                 Nothing -> []
                 Just _ -> [k]
+
+{- | Apply the specified changes to the given SyncCollection.  Returns
+a new SyncCollection with the changes applied.  If changes are specified
+that would apply to UIDs that do not exist in the source list, these changes
+are silently ignored. -}
+unaryApplyChanges :: (Eq k, Ord k, Show k) => 
+                     SyncCollection k -> [SyncCommand k] -> SyncCollection k
+unaryApplyChanges collection commands =
+    let makeChange collection (DeleteItem key) =
+            Map.delete key collection
+        makeChange collection (CopyItem key) =
+            Map.insert key () collection
+    in foldl makeChange collection commands