diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-06 18:29:15 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2023-10-06 18:29:15 +0200 |
commit | e5591eef3850a9796cc87386128651a828b70697 (patch) | |
tree | 7e501ec749229a3d96838265289266bb6f6ce208 /LibMatrix/Extensions/EnumerableExtensions.cs | |
parent | Unit tests, small refactors (diff) | |
download | LibMatrix-e5591eef3850a9796cc87386128651a828b70697.tar.xz |
Small refactors
Diffstat (limited to 'LibMatrix/Extensions/EnumerableExtensions.cs')
-rw-r--r-- | LibMatrix/Extensions/EnumerableExtensions.cs | 28 |
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); + } + } + +} |