about summary refs log tree commit diff
path: root/LibMatrix/Extensions/EnumerableExtensions.cs
blob: 42d94915927e7c1f2d971d3186cac699e2c4b76e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
namespace LibMatrix.Extensions;

public static class EnumerableExtensions {
    public static void MergeStateEventLists(this IList<StateEvent> oldState, IList<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 IList<StateEventResponse> oldState, IList<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);
        }
    }
}