Although you specifically mention that you are not using DistinctUntilChanged, you can use it with a counter for various new values:
public static IObservable<(T, TSecond)> ZipLatest<T, TSecond>(this IObservable<T> source, IObservable<TSecond> second) { return source.Select((value, id) => (value, id)) .CombineLatest(second.Select((value, id) => (value, id)), ValueTuple.Create) .DistinctUntilChanged(x => (x.Item1.id, x.Item2.id), new AnyEqualityComparer<int, int>()) .Select(x => (x.Item1.value, x.Item2.value)); } public class AnyEqualityComparer<T1, T2> : IEqualityComparer<(T1 a, T2 b)> { public bool Equals((T1 a, T2 b) x, (T1 a, T2 b) y) => Equals(xa, ya) || Equals(xb, yb); public int GetHashCode((T1 a, T2 b) obj) => throw new NotSupportedException(); }
Note that I used Int32 here - because it gives me Select (), but may be small for some use cases. Int64 or Guid may be the best choice.
source share