mirror of
				https://github.com/Kareadita/Kavita.git
				synced 2025-10-31 10:37:04 -04: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;
 | |
|                 }
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| } |