mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
25 lines
No EOL
727 B
C#
25 lines
No EOL
727 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace Ombi.Helpers
|
|
{
|
|
public static class LinqHelpers
|
|
{
|
|
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
|
|
{
|
|
HashSet<TKey> knownKeys = new HashSet<TKey>();
|
|
foreach (TSource source1 in source)
|
|
{
|
|
if (knownKeys.Add(keySelector(source1)))
|
|
yield return source1;
|
|
}
|
|
}
|
|
|
|
public static HashSet<T> ToHashSet<T>(
|
|
this IEnumerable<T> source,
|
|
IEqualityComparer<T> comparer = null)
|
|
{
|
|
return new HashSet<T>(source, comparer);
|
|
}
|
|
}
|
|
} |