Class DistinctUntilChangedOperator
Implements the DistinctUntilChanged operator. Mirrors rxjs's distinctUntilChanged.
public static class DistinctUntilChangedOperator
- Inheritance
-
System.ObjectDistinctUntilChangedOperator
Methods
DistinctUntilChanged<T>(Observable<T>, IEqualityComparer<T>?)
Emits a value from source only when it differs from the immediately preceding emitted
value, using comparer (or the default equality comparer for T).
public static Observable<T> DistinctUntilChanged<T>(this Observable<T> source, IEqualityComparer<T>? comparer = null)
Parameters
sourceObservable<T>The source observable to filter for consecutive distinct values.
comparerIEqualityComparer<T>?The comparer used to test equality. Defaults to EqualityComparer<T>.Default when null.
Returns
- Observable<T>
An observable that suppresses consecutive duplicate values from
source.
Type Parameters
TThe element type of the source observable.
Remarks
The first value is always emitted. Comparison is only ever against the last value that was actually
emitted downstream, not against every previously seen value — so a value can reappear later in the stream
if something different was emitted in between (e.g. 1, 1, 2, 1 emits 1, 2, 1).
DistinctUntilChanged<T, TKey>(Observable<T>, IEqualityComparer<TKey>, Func<T, TKey>)
Emits a value from source only when the key computed for it by keySelector
differs, per comparer, from the key computed for the immediately preceding emitted value.
public static Observable<T> DistinctUntilChanged<T, TKey>(this Observable<T> source, IEqualityComparer<TKey> comparer, Func<T, TKey> keySelector)
Parameters
sourceObservable<T>The source observable to filter for consecutive distinct keys.
comparerIEqualityComparer<TKey>The comparer used to test key equality.
keySelectorFunc<T, TKey>A function that extracts the comparison key from each value.
Returns
- Observable<T>
An observable that suppresses values whose key matches the previously emitted value's key.
Type Parameters
TThe element type of the source observable.
TKeyThe type of the key extracted from each value for comparison purposes.
Remarks
The first value is always emitted (after having its key computed). keySelector runs on
every value, including the first. Only the computed key is compared and retained between emissions; the
original value (not the key) is what gets emitted. If keySelector throws, the exception
is forwarded via OnError and the source subscription is torn down.
DistinctUntilKeyChanged<T, TKey>(Observable<T>, Func<T, TKey>, IEqualityComparer<TKey>?)
Emits a value from source only when the key computed for it by keySelector
differs, per comparer, from the key computed for the immediately preceding emitted value.
public static Observable<T> DistinctUntilKeyChanged<T, TKey>(this Observable<T> source, Func<T, TKey> keySelector, IEqualityComparer<TKey>? comparer = null)
Parameters
sourceObservable<T>The source observable to filter for consecutive distinct keys.
keySelectorFunc<T, TKey>A function that extracts the comparison key from each value.
comparerIEqualityComparer<TKey>?The comparer used to test key equality. Defaults to EqualityComparer<TKey>.Default when null.
Returns
- Observable<T>
An observable that suppresses values whose key matches the previously emitted value's key.
Type Parameters
TThe element type of the source observable.
TKeyThe type of the key extracted from each value for comparison purposes.
Remarks
A thin, more strongly-typed wrapper over DistinctUntilChanged<T, TKey>(Observable<T>, IEqualityComparer<TKey>, Func<T, TKey>)
— rxjs's distinctUntilKeyChanged takes a string property-name key (JS objects are dynamically
typed); this takes a keySelector function instead, the natural C# equivalent. The first
value is always emitted. If keySelector throws, the exception is forwarded via OnError.