MinMax.Generated.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  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<int> Max(this IAsyncEnumerable<int> source)
  12. {
  13. if (source == null)
  14. throw new ArgumentNullException(nameof(source));
  15. return source.Aggregate(Math.Max, CancellationToken.None);
  16. }
  17. public static Task<int> Max(this IAsyncEnumerable<int> source, CancellationToken cancellationToken)
  18. {
  19. if (source == null)
  20. throw new ArgumentNullException(nameof(source));
  21. return source.Aggregate(Math.Max, cancellationToken);
  22. }
  23. public static Task<int> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector)
  24. {
  25. if (source == null)
  26. throw new ArgumentNullException(nameof(source));
  27. if (selector == null)
  28. throw new ArgumentNullException(nameof(selector));
  29. return source.Select(selector).Max(CancellationToken.None);
  30. }
  31. public static Task<int> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
  32. {
  33. if (source == null)
  34. throw new ArgumentNullException(nameof(source));
  35. if (selector == null)
  36. throw new ArgumentNullException(nameof(selector));
  37. return source.Select(selector).Max(cancellationToken);
  38. }
  39. public static Task<long> Max(this IAsyncEnumerable<long> source)
  40. {
  41. if (source == null)
  42. throw new ArgumentNullException(nameof(source));
  43. return source.Aggregate(Math.Max, CancellationToken.None);
  44. }
  45. public static Task<long> Max(this IAsyncEnumerable<long> source, CancellationToken cancellationToken)
  46. {
  47. if (source == null)
  48. throw new ArgumentNullException(nameof(source));
  49. return source.Aggregate(Math.Max, cancellationToken);
  50. }
  51. public static Task<long> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector)
  52. {
  53. if (source == null)
  54. throw new ArgumentNullException(nameof(source));
  55. if (selector == null)
  56. throw new ArgumentNullException(nameof(selector));
  57. return source.Select(selector).Max(CancellationToken.None);
  58. }
  59. public static Task<long> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
  60. {
  61. if (source == null)
  62. throw new ArgumentNullException(nameof(source));
  63. if (selector == null)
  64. throw new ArgumentNullException(nameof(selector));
  65. return source.Select(selector).Max(cancellationToken);
  66. }
  67. public static Task<float> Max(this IAsyncEnumerable<float> source)
  68. {
  69. if (source == null)
  70. throw new ArgumentNullException(nameof(source));
  71. return source.Aggregate(Math.Max, CancellationToken.None);
  72. }
  73. public static Task<float> Max(this IAsyncEnumerable<float> source, CancellationToken cancellationToken)
  74. {
  75. if (source == null)
  76. throw new ArgumentNullException(nameof(source));
  77. return source.Aggregate(Math.Max, cancellationToken);
  78. }
  79. public static Task<float> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector)
  80. {
  81. if (source == null)
  82. throw new ArgumentNullException(nameof(source));
  83. if (selector == null)
  84. throw new ArgumentNullException(nameof(selector));
  85. return source.Select(selector).Max(CancellationToken.None);
  86. }
  87. public static Task<float> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
  88. {
  89. if (source == null)
  90. throw new ArgumentNullException(nameof(source));
  91. if (selector == null)
  92. throw new ArgumentNullException(nameof(selector));
  93. return source.Select(selector).Max(cancellationToken);
  94. }
  95. public static Task<double> Max(this IAsyncEnumerable<double> source)
  96. {
  97. if (source == null)
  98. throw new ArgumentNullException(nameof(source));
  99. return source.Aggregate(Math.Max, CancellationToken.None);
  100. }
  101. public static Task<double> Max(this IAsyncEnumerable<double> source, CancellationToken cancellationToken)
  102. {
  103. if (source == null)
  104. throw new ArgumentNullException(nameof(source));
  105. return source.Aggregate(Math.Max, cancellationToken);
  106. }
  107. public static Task<double> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector)
  108. {
  109. if (source == null)
  110. throw new ArgumentNullException(nameof(source));
  111. if (selector == null)
  112. throw new ArgumentNullException(nameof(selector));
  113. return source.Select(selector).Max(CancellationToken.None);
  114. }
  115. public static Task<double> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
  116. {
  117. if (source == null)
  118. throw new ArgumentNullException(nameof(source));
  119. if (selector == null)
  120. throw new ArgumentNullException(nameof(selector));
  121. return source.Select(selector).Max(cancellationToken);
  122. }
  123. public static Task<decimal> Max(this IAsyncEnumerable<decimal> source)
  124. {
  125. if (source == null)
  126. throw new ArgumentNullException(nameof(source));
  127. return source.Aggregate(Math.Max, CancellationToken.None);
  128. }
  129. public static Task<decimal> Max(this IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
  130. {
  131. if (source == null)
  132. throw new ArgumentNullException(nameof(source));
  133. return source.Aggregate(Math.Max, cancellationToken);
  134. }
  135. public static Task<decimal> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector)
  136. {
  137. if (source == null)
  138. throw new ArgumentNullException(nameof(source));
  139. if (selector == null)
  140. throw new ArgumentNullException(nameof(selector));
  141. return source.Select(selector).Max(CancellationToken.None);
  142. }
  143. public static Task<decimal> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
  144. {
  145. if (source == null)
  146. throw new ArgumentNullException(nameof(source));
  147. if (selector == null)
  148. throw new ArgumentNullException(nameof(selector));
  149. return source.Select(selector).Max(cancellationToken);
  150. }
  151. public static Task<int?> Max(this IAsyncEnumerable<int?> source)
  152. {
  153. if (source == null)
  154. throw new ArgumentNullException(nameof(source));
  155. return source.Aggregate(default(int?), NullableMax, CancellationToken.None);
  156. }
  157. public static Task<int?> Max(this IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
  158. {
  159. if (source == null)
  160. throw new ArgumentNullException(nameof(source));
  161. return source.Aggregate(default(int?), NullableMax, cancellationToken);
  162. }
  163. public static Task<int?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector)
  164. {
  165. if (source == null)
  166. throw new ArgumentNullException(nameof(source));
  167. if (selector == null)
  168. throw new ArgumentNullException(nameof(selector));
  169. return source.Select(selector).Max(CancellationToken.None);
  170. }
  171. public static Task<int?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
  172. {
  173. if (source == null)
  174. throw new ArgumentNullException(nameof(source));
  175. if (selector == null)
  176. throw new ArgumentNullException(nameof(selector));
  177. return source.Select(selector).Max(cancellationToken);
  178. }
  179. public static Task<long?> Max(this IAsyncEnumerable<long?> source)
  180. {
  181. if (source == null)
  182. throw new ArgumentNullException(nameof(source));
  183. return source.Aggregate(default(long?), NullableMax, CancellationToken.None);
  184. }
  185. public static Task<long?> Max(this IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
  186. {
  187. if (source == null)
  188. throw new ArgumentNullException(nameof(source));
  189. return source.Aggregate(default(long?), NullableMax, cancellationToken);
  190. }
  191. public static Task<long?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector)
  192. {
  193. if (source == null)
  194. throw new ArgumentNullException(nameof(source));
  195. if (selector == null)
  196. throw new ArgumentNullException(nameof(selector));
  197. return source.Select(selector).Max(CancellationToken.None);
  198. }
  199. public static Task<long?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
  200. {
  201. if (source == null)
  202. throw new ArgumentNullException(nameof(source));
  203. if (selector == null)
  204. throw new ArgumentNullException(nameof(selector));
  205. return source.Select(selector).Max(cancellationToken);
  206. }
  207. public static Task<float?> Max(this IAsyncEnumerable<float?> source)
  208. {
  209. if (source == null)
  210. throw new ArgumentNullException(nameof(source));
  211. return source.Aggregate(default(float?), NullableMax, CancellationToken.None);
  212. }
  213. public static Task<float?> Max(this IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
  214. {
  215. if (source == null)
  216. throw new ArgumentNullException(nameof(source));
  217. return source.Aggregate(default(float?), NullableMax, cancellationToken);
  218. }
  219. public static Task<float?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector)
  220. {
  221. if (source == null)
  222. throw new ArgumentNullException(nameof(source));
  223. if (selector == null)
  224. throw new ArgumentNullException(nameof(selector));
  225. return source.Select(selector).Max(CancellationToken.None);
  226. }
  227. public static Task<float?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
  228. {
  229. if (source == null)
  230. throw new ArgumentNullException(nameof(source));
  231. if (selector == null)
  232. throw new ArgumentNullException(nameof(selector));
  233. return source.Select(selector).Max(cancellationToken);
  234. }
  235. public static Task<double?> Max(this IAsyncEnumerable<double?> source)
  236. {
  237. if (source == null)
  238. throw new ArgumentNullException(nameof(source));
  239. return source.Aggregate(default(double?), NullableMax, CancellationToken.None);
  240. }
  241. public static Task<double?> Max(this IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
  242. {
  243. if (source == null)
  244. throw new ArgumentNullException(nameof(source));
  245. return source.Aggregate(default(double?), NullableMax, cancellationToken);
  246. }
  247. public static Task<double?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector)
  248. {
  249. if (source == null)
  250. throw new ArgumentNullException(nameof(source));
  251. if (selector == null)
  252. throw new ArgumentNullException(nameof(selector));
  253. return source.Select(selector).Max(CancellationToken.None);
  254. }
  255. public static Task<double?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
  256. {
  257. if (source == null)
  258. throw new ArgumentNullException(nameof(source));
  259. if (selector == null)
  260. throw new ArgumentNullException(nameof(selector));
  261. return source.Select(selector).Max(cancellationToken);
  262. }
  263. public static Task<decimal?> Max(this IAsyncEnumerable<decimal?> source)
  264. {
  265. if (source == null)
  266. throw new ArgumentNullException(nameof(source));
  267. return source.Aggregate(default(decimal?), NullableMax, CancellationToken.None);
  268. }
  269. public static Task<decimal?> Max(this IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
  270. {
  271. if (source == null)
  272. throw new ArgumentNullException(nameof(source));
  273. return source.Aggregate(default(decimal?), NullableMax, cancellationToken);
  274. }
  275. public static Task<decimal?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector)
  276. {
  277. if (source == null)
  278. throw new ArgumentNullException(nameof(source));
  279. if (selector == null)
  280. throw new ArgumentNullException(nameof(selector));
  281. return source.Select(selector).Max(CancellationToken.None);
  282. }
  283. public static Task<decimal?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
  284. {
  285. if (source == null)
  286. throw new ArgumentNullException(nameof(source));
  287. if (selector == null)
  288. throw new ArgumentNullException(nameof(selector));
  289. return source.Select(selector).Max(cancellationToken);
  290. }
  291. public static Task<int> Min(this IAsyncEnumerable<int> source)
  292. {
  293. if (source == null)
  294. throw new ArgumentNullException(nameof(source));
  295. return source.Aggregate(Math.Min, CancellationToken.None);
  296. }
  297. public static Task<int> Min(this IAsyncEnumerable<int> source, CancellationToken cancellationToken)
  298. {
  299. if (source == null)
  300. throw new ArgumentNullException(nameof(source));
  301. return source.Aggregate(Math.Min, cancellationToken);
  302. }
  303. public static Task<int> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector)
  304. {
  305. if (source == null)
  306. throw new ArgumentNullException(nameof(source));
  307. if (selector == null)
  308. throw new ArgumentNullException(nameof(selector));
  309. return source.Select(selector).Min(CancellationToken.None);
  310. }
  311. public static Task<int> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
  312. {
  313. if (source == null)
  314. throw new ArgumentNullException(nameof(source));
  315. if (selector == null)
  316. throw new ArgumentNullException(nameof(selector));
  317. return source.Select(selector).Min(cancellationToken);
  318. }
  319. public static Task<long> Min(this IAsyncEnumerable<long> source)
  320. {
  321. if (source == null)
  322. throw new ArgumentNullException(nameof(source));
  323. return source.Aggregate(Math.Min, CancellationToken.None);
  324. }
  325. public static Task<long> Min(this IAsyncEnumerable<long> source, CancellationToken cancellationToken)
  326. {
  327. if (source == null)
  328. throw new ArgumentNullException(nameof(source));
  329. return source.Aggregate(Math.Min, cancellationToken);
  330. }
  331. public static Task<long> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector)
  332. {
  333. if (source == null)
  334. throw new ArgumentNullException(nameof(source));
  335. if (selector == null)
  336. throw new ArgumentNullException(nameof(selector));
  337. return source.Select(selector).Min(CancellationToken.None);
  338. }
  339. public static Task<long> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
  340. {
  341. if (source == null)
  342. throw new ArgumentNullException(nameof(source));
  343. if (selector == null)
  344. throw new ArgumentNullException(nameof(selector));
  345. return source.Select(selector).Min(cancellationToken);
  346. }
  347. public static Task<float> Min(this IAsyncEnumerable<float> source)
  348. {
  349. if (source == null)
  350. throw new ArgumentNullException(nameof(source));
  351. return source.Aggregate(Math.Min, CancellationToken.None);
  352. }
  353. public static Task<float> Min(this IAsyncEnumerable<float> source, CancellationToken cancellationToken)
  354. {
  355. if (source == null)
  356. throw new ArgumentNullException(nameof(source));
  357. return source.Aggregate(Math.Min, cancellationToken);
  358. }
  359. public static Task<float> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector)
  360. {
  361. if (source == null)
  362. throw new ArgumentNullException(nameof(source));
  363. if (selector == null)
  364. throw new ArgumentNullException(nameof(selector));
  365. return source.Select(selector).Min(CancellationToken.None);
  366. }
  367. public static Task<float> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
  368. {
  369. if (source == null)
  370. throw new ArgumentNullException(nameof(source));
  371. if (selector == null)
  372. throw new ArgumentNullException(nameof(selector));
  373. return source.Select(selector).Min(cancellationToken);
  374. }
  375. public static Task<double> Min(this IAsyncEnumerable<double> source)
  376. {
  377. if (source == null)
  378. throw new ArgumentNullException(nameof(source));
  379. return source.Aggregate(Math.Min, CancellationToken.None);
  380. }
  381. public static Task<double> Min(this IAsyncEnumerable<double> source, CancellationToken cancellationToken)
  382. {
  383. if (source == null)
  384. throw new ArgumentNullException(nameof(source));
  385. return source.Aggregate(Math.Min, cancellationToken);
  386. }
  387. public static Task<double> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector)
  388. {
  389. if (source == null)
  390. throw new ArgumentNullException(nameof(source));
  391. if (selector == null)
  392. throw new ArgumentNullException(nameof(selector));
  393. return source.Select(selector).Min(CancellationToken.None);
  394. }
  395. public static Task<double> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
  396. {
  397. if (source == null)
  398. throw new ArgumentNullException(nameof(source));
  399. if (selector == null)
  400. throw new ArgumentNullException(nameof(selector));
  401. return source.Select(selector).Min(cancellationToken);
  402. }
  403. public static Task<decimal> Min(this IAsyncEnumerable<decimal> source)
  404. {
  405. if (source == null)
  406. throw new ArgumentNullException(nameof(source));
  407. return source.Aggregate(Math.Min, CancellationToken.None);
  408. }
  409. public static Task<decimal> Min(this IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
  410. {
  411. if (source == null)
  412. throw new ArgumentNullException(nameof(source));
  413. return source.Aggregate(Math.Min, cancellationToken);
  414. }
  415. public static Task<decimal> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector)
  416. {
  417. if (source == null)
  418. throw new ArgumentNullException(nameof(source));
  419. if (selector == null)
  420. throw new ArgumentNullException(nameof(selector));
  421. return source.Select(selector).Min(CancellationToken.None);
  422. }
  423. public static Task<decimal> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
  424. {
  425. if (source == null)
  426. throw new ArgumentNullException(nameof(source));
  427. if (selector == null)
  428. throw new ArgumentNullException(nameof(selector));
  429. return source.Select(selector).Min(cancellationToken);
  430. }
  431. public static Task<int?> Min(this IAsyncEnumerable<int?> source)
  432. {
  433. if (source == null)
  434. throw new ArgumentNullException(nameof(source));
  435. return source.Aggregate(default(int?), NullableMin, CancellationToken.None);
  436. }
  437. public static Task<int?> Min(this IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
  438. {
  439. if (source == null)
  440. throw new ArgumentNullException(nameof(source));
  441. return source.Aggregate(default(int?), NullableMin, cancellationToken);
  442. }
  443. public static Task<int?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector)
  444. {
  445. if (source == null)
  446. throw new ArgumentNullException(nameof(source));
  447. if (selector == null)
  448. throw new ArgumentNullException(nameof(selector));
  449. return source.Select(selector).Min(CancellationToken.None);
  450. }
  451. public static Task<int?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
  452. {
  453. if (source == null)
  454. throw new ArgumentNullException(nameof(source));
  455. if (selector == null)
  456. throw new ArgumentNullException(nameof(selector));
  457. return source.Select(selector).Min(cancellationToken);
  458. }
  459. public static Task<long?> Min(this IAsyncEnumerable<long?> source)
  460. {
  461. if (source == null)
  462. throw new ArgumentNullException(nameof(source));
  463. return source.Aggregate(default(long?), NullableMin, CancellationToken.None);
  464. }
  465. public static Task<long?> Min(this IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
  466. {
  467. if (source == null)
  468. throw new ArgumentNullException(nameof(source));
  469. return source.Aggregate(default(long?), NullableMin, cancellationToken);
  470. }
  471. public static Task<long?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector)
  472. {
  473. if (source == null)
  474. throw new ArgumentNullException(nameof(source));
  475. if (selector == null)
  476. throw new ArgumentNullException(nameof(selector));
  477. return source.Select(selector).Min(CancellationToken.None);
  478. }
  479. public static Task<long?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
  480. {
  481. if (source == null)
  482. throw new ArgumentNullException(nameof(source));
  483. if (selector == null)
  484. throw new ArgumentNullException(nameof(selector));
  485. return source.Select(selector).Min(cancellationToken);
  486. }
  487. public static Task<float?> Min(this IAsyncEnumerable<float?> source)
  488. {
  489. if (source == null)
  490. throw new ArgumentNullException(nameof(source));
  491. return source.Aggregate(default(float?), NullableMin, CancellationToken.None);
  492. }
  493. public static Task<float?> Min(this IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
  494. {
  495. if (source == null)
  496. throw new ArgumentNullException(nameof(source));
  497. return source.Aggregate(default(float?), NullableMin, cancellationToken);
  498. }
  499. public static Task<float?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector)
  500. {
  501. if (source == null)
  502. throw new ArgumentNullException(nameof(source));
  503. if (selector == null)
  504. throw new ArgumentNullException(nameof(selector));
  505. return source.Select(selector).Min(CancellationToken.None);
  506. }
  507. public static Task<float?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
  508. {
  509. if (source == null)
  510. throw new ArgumentNullException(nameof(source));
  511. if (selector == null)
  512. throw new ArgumentNullException(nameof(selector));
  513. return source.Select(selector).Min(cancellationToken);
  514. }
  515. public static Task<double?> Min(this IAsyncEnumerable<double?> source)
  516. {
  517. if (source == null)
  518. throw new ArgumentNullException(nameof(source));
  519. return source.Aggregate(default(double?), NullableMin, CancellationToken.None);
  520. }
  521. public static Task<double?> Min(this IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
  522. {
  523. if (source == null)
  524. throw new ArgumentNullException(nameof(source));
  525. return source.Aggregate(default(double?), NullableMin, cancellationToken);
  526. }
  527. public static Task<double?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector)
  528. {
  529. if (source == null)
  530. throw new ArgumentNullException(nameof(source));
  531. if (selector == null)
  532. throw new ArgumentNullException(nameof(selector));
  533. return source.Select(selector).Min(CancellationToken.None);
  534. }
  535. public static Task<double?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
  536. {
  537. if (source == null)
  538. throw new ArgumentNullException(nameof(source));
  539. if (selector == null)
  540. throw new ArgumentNullException(nameof(selector));
  541. return source.Select(selector).Min(cancellationToken);
  542. }
  543. public static Task<decimal?> Min(this IAsyncEnumerable<decimal?> source)
  544. {
  545. if (source == null)
  546. throw new ArgumentNullException(nameof(source));
  547. return source.Aggregate(default(decimal?), NullableMin, CancellationToken.None);
  548. }
  549. public static Task<decimal?> Min(this IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
  550. {
  551. if (source == null)
  552. throw new ArgumentNullException(nameof(source));
  553. return source.Aggregate(default(decimal?), NullableMin, cancellationToken);
  554. }
  555. public static Task<decimal?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector)
  556. {
  557. if (source == null)
  558. throw new ArgumentNullException(nameof(source));
  559. if (selector == null)
  560. throw new ArgumentNullException(nameof(selector));
  561. return source.Select(selector).Min(CancellationToken.None);
  562. }
  563. public static Task<decimal?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
  564. {
  565. if (source == null)
  566. throw new ArgumentNullException(nameof(source));
  567. if (selector == null)
  568. throw new ArgumentNullException(nameof(selector));
  569. return source.Select(selector).Min(cancellationToken);
  570. }
  571. private static T? NullableMax<T>(T? x, T? y)
  572. where T : struct, IComparable<T>
  573. {
  574. if (!x.HasValue)
  575. return y;
  576. if (!y.HasValue)
  577. return x;
  578. if (x.Value.CompareTo(y.Value) >= 0)
  579. return x;
  580. return y;
  581. }
  582. private static T? NullableMin<T>(T? x, T? y)
  583. where T : struct, IComparable<T>
  584. {
  585. if (!x.HasValue)
  586. return y;
  587. if (!y.HasValue)
  588. return x;
  589. if (x.Value.CompareTo(y.Value) <= 0)
  590. return x;
  591. return y;
  592. }
  593. }
  594. }