添加元组、AnalysisLevel、DistinctBy 的 PLINQ 形式
This commit is contained in:
1 parent
6e0c722be1
commit
71027af206
2 files changed
+12
-1
No files matched your search
@@ -1,4 +1,6 @@
|
||||
namespace MeloongCore.Extensions;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace MeloongCore.Extensions;
|
||||
public static class EnumerableExtensions {
|
||||
|
||||
#region Distinct
|
||||
@@ -21,6 +23,13 @@ public static class EnumerableExtensions {
|
||||
if (seen.Add(selector(element))) yield return element;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 按对象的指定值去重。
|
||||
/// </summary>
|
||||
public static ParallelQuery<T> DistinctBy<T, TKey>(this ParallelQuery<T> source, Func<T, TKey> selector) {
|
||||
var seen = new ConcurrentDictionary<TKey, bool>();
|
||||
return source.Where(element => seen.TryAdd(selector(element), true));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
Reference in new issue
Block a user