mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-05-24 00:52:23 -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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |