<PackageReference Include="System.Reactive" Version="6.0.0-preview.16" />
    
    
	
	
		
		
		
	 
	
	
        
                
                Distinct<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 Distinct<[
System.
Runtime.
CompilerServices.
Nullable(
2)] 
TSource, [
System.
Runtime.
CompilerServices.
Nullable(
2)] 
TKey> : 
Producer<
TSource, 
Distinct<
TSource, 
TKey>.
_>
    {
        [
System.
Runtime.
CompilerServices.
Nullable(
new byte[] {
            
0,
            
1
        })]
        
internal sealed class _ : 
IdentitySink<
TSource>
        {
            
private readonly Func<
TSource, 
TKey> 
_keySelector;
            
private readonly HashSet<
TKey> 
_hashSet;
            
public _(
Distinct<
TSource, 
TKey> 
parent, 
IObserver<
TSource> 
observer)
                : 
base(
observer)
            {
                
_keySelector = 
parent.
_keySelector;
                
_hashSet = 
new HashSet<
TKey>(
parent.
_comparer);
            }
            
public override void OnNext(
TSource value)
            {
                
bool flag;
                
try {
                    
TKey item = 
_keySelector(
value);
                    
flag = 
_hashSet.
Add(
item);
                } 
catch (
Exception error) {
                    
ForwardOnError(
error);
                    
return;
                }
                
if (
flag)
                    
ForwardOnNext(
value);
            }
        }
        
private readonly IObservable<
TSource> 
_source;
        
private readonly Func<
TSource, 
TKey> 
_keySelector;
        
private readonly IEqualityComparer<
TKey> 
_comparer;
        
public Distinct(
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);
        }
    }
}