mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Use customized distinctBy instead of customized equalitycomparator
This commit is contained in:
parent
a4160a14e8
commit
276395e5f4
1 changed files with 6 additions and 12 deletions
|
|
@ -446,18 +446,13 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
}
|
||||
}
|
||||
|
||||
private class Win32ComparatorWithDescription : IEqualityComparer<Win32>
|
||||
public static IEnumerable<T> DistinctBy<T, R>(IEnumerable<T> source, Func<T,R> selector)
|
||||
{
|
||||
public static readonly Win32ComparatorWithDescription Default = new Win32ComparatorWithDescription();
|
||||
|
||||
public bool Equals(Win32 x, Win32 y)
|
||||
var set = new HashSet<R>();
|
||||
foreach (var item in source)
|
||||
{
|
||||
return x?.Description == y?.Description;
|
||||
}
|
||||
|
||||
public int GetHashCode(Win32 obj)
|
||||
{
|
||||
return obj.Description.GetHashCode();
|
||||
if (set.Add(selector(item)))
|
||||
yield return item;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -467,8 +462,7 @@ namespace Flow.Launcher.Plugin.Program.Programs
|
|||
.SelectMany(g =>
|
||||
{
|
||||
if (g.Count() > 1)
|
||||
return g.Where(p => !string.IsNullOrEmpty(p.Description))
|
||||
.Distinct(Win32ComparatorWithDescription.Default);
|
||||
return DistinctBy(g.Where(p => !string.IsNullOrEmpty(p.Description)), x => x.Description);
|
||||
return g;
|
||||
}).ToArray();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue