Union.cs 1.1 KB

1234567891011121314151617181920212223242526
  1. using Cysharp.Threading.Tasks.Internal;
  2. using System.Collections.Generic;
  3. namespace Cysharp.Threading.Tasks.Linq
  4. {
  5. public static partial class UniTaskAsyncEnumerable
  6. {
  7. public static IUniTaskAsyncEnumerable<TSource> Union<TSource>(this IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second)
  8. {
  9. Error.ThrowArgumentNullException(first, nameof(first));
  10. Error.ThrowArgumentNullException(second, nameof(second));
  11. return Union<TSource>(first, second, EqualityComparer<TSource>.Default);
  12. }
  13. public static IUniTaskAsyncEnumerable<TSource> Union<TSource>(this IUniTaskAsyncEnumerable<TSource> first, IUniTaskAsyncEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
  14. {
  15. Error.ThrowArgumentNullException(first, nameof(first));
  16. Error.ThrowArgumentNullException(second, nameof(second));
  17. Error.ThrowArgumentNullException(comparer, nameof(comparer));
  18. // improv without combinate?
  19. return first.Concat(second).Distinct(comparer);
  20. }
  21. }
  22. }