Min.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the Apache 2.0 License.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Collections.Generic;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. namespace System.Linq
  8. {
  9. public static partial class AsyncEnumerable
  10. {
  11. public static Task<TSource> MinAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken cancellationToken = default)
  12. {
  13. if (source == null)
  14. throw Error.ArgumentNull(nameof(source));
  15. return MinCore(source, cancellationToken);
  16. }
  17. public static Task<TResult> MinAsync<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TResult> selector, CancellationToken cancellationToken = default)
  18. {
  19. if (source == null)
  20. throw Error.ArgumentNull(nameof(source));
  21. if (selector == null)
  22. throw Error.ArgumentNull(nameof(selector));
  23. return MinCore(source, selector, cancellationToken);
  24. }
  25. public static Task<TResult> MinAsync<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TResult>> selector, CancellationToken cancellationToken = default)
  26. {
  27. if (source == null)
  28. throw Error.ArgumentNull(nameof(source));
  29. if (selector == null)
  30. throw Error.ArgumentNull(nameof(selector));
  31. return MinCore(source, selector, cancellationToken);
  32. }
  33. #if !NO_DEEP_CANCELLATION
  34. public static Task<TResult> MinAsync<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<TResult>> selector, CancellationToken cancellationToken = default)
  35. {
  36. if (source == null)
  37. throw Error.ArgumentNull(nameof(source));
  38. if (selector == null)
  39. throw Error.ArgumentNull(nameof(selector));
  40. return MinCore(source, selector, cancellationToken);
  41. }
  42. #endif
  43. }
  44. }