<PackageReference Include="System.Reactive" Version="6.0.0-preview.13" />
    
    
	
	
		
		
		
	 
	
	
        
                
                DistinctUntilChanged<TSource, TKey>
                
                
                
                
using System.
Collections.
Generic;
using System.
Runtime.
CompilerServices;
namespace System.
Reactive.
Linq.
ObservableImpl
{
    [
System.
Runtime.
CompilerServices.
NullableContext(
1)]
    [
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
        
0,
        
1,
        
1,
        
1,
        
1
    })]
    
internal sealed class DistinctUntilChanged<[
System.
Runtime.
CompilerServices.
Nullable(
2)] 
TSource, [
System.
Runtime.
CompilerServices.
Nullable(
2)] 
TKey> : 
Producer<
TSource, 
DistinctUntilChanged<
TSource, 
TKey>.
_>
    {
        [
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
            
0,
            
1
        })]
        
internal sealed class _ : 
IdentitySink<
TSource>
        {
            
private readonly Func<
TSource, 
TKey> 
_keySelector;
            
private readonly IEqualityComparer<
TKey> 
_comparer;
            [
System.
Runtime.
CompilerServices.
Nullable(
2)]
            
private TKey _currentKey;
            
private bool _hasCurrentKey;
            
public _(
DistinctUntilChanged<
TSource, 
TKey> 
parent, 
IObserver<
TSource> 
observer)
                : 
base(
observer)
            {
                
_keySelector = 
parent.
_keySelector;
                
_comparer = 
parent.
_comparer;
            }
            
public override void OnNext(
TSource value)
            {
                
TKey val;
                
try {
                    
val = 
_keySelector(
value);
                } 
catch (
Exception error) {
                    
ForwardOnError(
error);
                    
return;
                }
                
bool flag = 
false;
                
if (
_hasCurrentKey)
                    
try {
                        
flag = 
_comparer.
Equals(
_currentKey, 
val);
                    } 
catch (
Exception error2) {
                        
ForwardOnError(
error2);
                        
return;
                    }
                
if (!
_hasCurrentKey || !
flag) {
                    
_hasCurrentKey = 
true;
                    
_currentKey = 
val;
                    
ForwardOnNext(
value);
                }
            }
        }
        
private readonly IObservable<
TSource> 
_source;
        
private readonly Func<
TSource, 
TKey> 
_keySelector;
        
private readonly IEqualityComparer<
TKey> 
_comparer;
        
public DistinctUntilChanged(
IObservable<
TSource> 
source, 
Func<
TSource, 
TKey> 
keySelector, 
IEqualityComparer<
TKey> 
comparer)
        {
            
_source = 
source;
            
_keySelector = 
keySelector;
            
_comparer = 
comparer;
        }
        [
return: 
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
            
1,
            
0,
            
0
        })]
        
protected override _ CreateSink(
IObserver<
TSource> 
observer)
        {
            
return new _(
this, 
observer);
        }
        
protected override void Run([
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
            
1,
            
0,
            
0
        })] 
_ sink)
        {
            
sink.
Run(
_source);
        }
    }
}