Reactive operator for distinct values that must change by amount I would like feedback on this DistinctUntilChangedBy operator for System.Reactive that only emits when the current value is different than the last by a specified amount. Is there a better implementation?

I want to avoid multiple emits when the stream looks like this: 0.80, 0.81, 0.80, 0.81, etc.

Using the operator like this:

stream.DistinctUntilChangedBy(0.01).Subscribe(x =&gt; Console.WriteLine(x));


Should output this:

0.80


The operator looks like this and it is also on GitHub as a gist:

using System;
using System.Collections.Generic;
using System.Reactive.Linq;

namespace Gists.Reactive.Linq
{
    public static partial class ObservableExtensions
    {
        ///&lt;summary&gt;
        ///Only emit when the current value is different than the last by the specified amount.
        ///&lt;/summary&gt;    
        public static IObservable&lt;decimal&gt; DistinctUntilChangedBy(this IObservable&lt;decimal&gt; source, decimal amount)
        {
            return source.DistinctUntilChanged(new DistinctUntilChangedByEqualityComparer(amount));
        }

        private class DistinctUntilChangedByEqualityComparer : IEqualityComparer&lt;decimal&gt;
        {
            private readonly decimal amount;

            public DistinctUntilChangedByEqualityComparer(decimal amount)
            {
                this.amount = amount;
            }

            public bool Equals(decimal x, decimal y)
            {
                var diff = Math.Abs(x - y);
                return diff &lt;= Math.Abs(amount);
            }

            public int GetHashCode(decimal obj)
            {
                throw new NotSupportedException();
            }
        }
    }
}
DistinctUntilChangedBy()
This method is public and therefore should do proper argument validation. Since this method is an extension-method, it could be called like:
ObservableExtensions.DistinctUntilChangedBy(someObservable, someDecimal);

If someObservableis null, your method would throw a NullReferenceException where an ArgumentNullException would be a better fit.
Equals(decimal, decimal)
Instead of returning diff &lt;= Math.Abs(amount) you could set the class variable amount in the constructor directly to the Abs(amount) of the passed argument:
this.amount = Math.Abs(amount)

That could speed it up if the Equals() method is called often.
GetHashCode(decimal)
Only if you are 100% sure that this method won't ever be called should you throw a NotSupportedException. See What's the role of GetHashCode in the IEqualityComparer&lt;T&gt; in .NET?