about summary refs log tree commit diff
path: root/LibMatrix/Extensions/EnumerableExtensions.cs
diff options
context:
space:
mode:
authorTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-06 18:29:15 +0200
committerTheArcaneBrony <myrainbowdash949@gmail.com>2023-10-06 18:29:15 +0200
commite5591eef3850a9796cc87386128651a828b70697 (patch)
tree7e501ec749229a3d96838265289266bb6f6ce208 /LibMatrix/Extensions/EnumerableExtensions.cs
parentUnit tests, small refactors (diff)
downloadLibMatrix-e5591eef3850a9796cc87386128651a828b70697.tar.xz
Small refactors
Diffstat (limited to 'LibMatrix/Extensions/EnumerableExtensions.cs')
-rw-r--r--LibMatrix/Extensions/EnumerableExtensions.cs28
1 files changed, 28 insertions, 0 deletions
diff --git a/LibMatrix/Extensions/EnumerableExtensions.cs b/LibMatrix/Extensions/EnumerableExtensions.cs
new file mode 100644
index 0000000..d9619b7
--- /dev/null
+++ b/LibMatrix/Extensions/EnumerableExtensions.cs
@@ -0,0 +1,28 @@
+namespace LibMatrix.Extensions;
+
+public static class EnumerableExtensions {
+    public static void MergeStateEventLists(this List<StateEvent> oldState, List<StateEvent> newState) {
+        foreach (var stateEvent in newState) {
+            var old = oldState.FirstOrDefault(x => x.Type == stateEvent.Type && x.StateKey == stateEvent.StateKey);
+            if (old is null) {
+                oldState.Add(stateEvent);
+                continue;
+            }
+            oldState.Remove(old);
+            oldState.Add(stateEvent);
+        }
+    }
+
+    public static void MergeStateEventLists(this List<StateEventResponse> oldState, List<StateEventResponse> newState) {
+        foreach (var stateEvent in newState) {
+            var old = oldState.FirstOrDefault(x => x.Type == stateEvent.Type && x.StateKey == stateEvent.StateKey);
+            if (old is null) {
+                oldState.Add(stateEvent);
+                continue;
+            }
+            oldState.Remove(old);
+            oldState.Add(stateEvent);
+        }
+    }
+
+}