mirror of
				https://github.com/Kareadita/Kavita.git
				synced 2025-11-04 03:27:05 -05:00 
			
		
		
		
	
		
			
				
	
	
		
			21 lines
		
	
	
		
			560 B
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			21 lines
		
	
	
		
			560 B
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Collections.Generic;
 | 
						|
 | 
						|
namespace API.Extensions
 | 
						|
{
 | 
						|
    public static class EnumerableExtensions
 | 
						|
    {
 | 
						|
        public static IEnumerable<TSource> DistinctBy<TSource, TKey>
 | 
						|
            (this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
 | 
						|
        {
 | 
						|
            var seenKeys = new HashSet<TKey>();
 | 
						|
            foreach (var element in source)
 | 
						|
            {
 | 
						|
                if (seenKeys.Add(keySelector(element)))
 | 
						|
                {
 | 
						|
                    yield return element;
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
    }
 | 
						|
} |