MinMax.Generated.cs 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157
  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(new Func<int, int, int>(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(new Func<int, int, int>(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<int> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int>> selector)
  40. {
  41. if (source == null)
  42. throw new ArgumentNullException(nameof(source));
  43. if (selector == null)
  44. throw new ArgumentNullException(nameof(selector));
  45. return source.Select(selector).Max(CancellationToken.None);
  46. }
  47. public static Task<int> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int>> selector, CancellationToken cancellationToken)
  48. {
  49. if (source == null)
  50. throw new ArgumentNullException(nameof(source));
  51. if (selector == null)
  52. throw new ArgumentNullException(nameof(selector));
  53. return source.Select(selector).Max(cancellationToken);
  54. }
  55. public static Task<long> Max(this IAsyncEnumerable<long> source)
  56. {
  57. if (source == null)
  58. throw new ArgumentNullException(nameof(source));
  59. return source.Aggregate(new Func<long, long, long>(Math.Max), CancellationToken.None);
  60. }
  61. public static Task<long> Max(this IAsyncEnumerable<long> source, CancellationToken cancellationToken)
  62. {
  63. if (source == null)
  64. throw new ArgumentNullException(nameof(source));
  65. return source.Aggregate(new Func<long, long, long>(Math.Max), cancellationToken);
  66. }
  67. public static Task<long> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector)
  68. {
  69. if (source == null)
  70. throw new ArgumentNullException(nameof(source));
  71. if (selector == null)
  72. throw new ArgumentNullException(nameof(selector));
  73. return source.Select(selector).Max(CancellationToken.None);
  74. }
  75. public static Task<long> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
  76. {
  77. if (source == null)
  78. throw new ArgumentNullException(nameof(source));
  79. if (selector == null)
  80. throw new ArgumentNullException(nameof(selector));
  81. return source.Select(selector).Max(cancellationToken);
  82. }
  83. public static Task<long> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long>> selector)
  84. {
  85. if (source == null)
  86. throw new ArgumentNullException(nameof(source));
  87. if (selector == null)
  88. throw new ArgumentNullException(nameof(selector));
  89. return source.Select(selector).Max(CancellationToken.None);
  90. }
  91. public static Task<long> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long>> selector, CancellationToken cancellationToken)
  92. {
  93. if (source == null)
  94. throw new ArgumentNullException(nameof(source));
  95. if (selector == null)
  96. throw new ArgumentNullException(nameof(selector));
  97. return source.Select(selector).Max(cancellationToken);
  98. }
  99. public static Task<float> Max(this IAsyncEnumerable<float> source)
  100. {
  101. if (source == null)
  102. throw new ArgumentNullException(nameof(source));
  103. return source.Aggregate(new Func<float, float, float>(Math.Max), CancellationToken.None);
  104. }
  105. public static Task<float> Max(this IAsyncEnumerable<float> source, CancellationToken cancellationToken)
  106. {
  107. if (source == null)
  108. throw new ArgumentNullException(nameof(source));
  109. return source.Aggregate(new Func<float, float, float>(Math.Max), cancellationToken);
  110. }
  111. public static Task<float> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector)
  112. {
  113. if (source == null)
  114. throw new ArgumentNullException(nameof(source));
  115. if (selector == null)
  116. throw new ArgumentNullException(nameof(selector));
  117. return source.Select(selector).Max(CancellationToken.None);
  118. }
  119. public static Task<float> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
  120. {
  121. if (source == null)
  122. throw new ArgumentNullException(nameof(source));
  123. if (selector == null)
  124. throw new ArgumentNullException(nameof(selector));
  125. return source.Select(selector).Max(cancellationToken);
  126. }
  127. public static Task<float> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float>> selector)
  128. {
  129. if (source == null)
  130. throw new ArgumentNullException(nameof(source));
  131. if (selector == null)
  132. throw new ArgumentNullException(nameof(selector));
  133. return source.Select(selector).Max(CancellationToken.None);
  134. }
  135. public static Task<float> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float>> selector, CancellationToken cancellationToken)
  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);
  142. }
  143. public static Task<double> Max(this IAsyncEnumerable<double> source)
  144. {
  145. if (source == null)
  146. throw new ArgumentNullException(nameof(source));
  147. return source.Aggregate(new Func<double, double, double>(Math.Max), CancellationToken.None);
  148. }
  149. public static Task<double> Max(this IAsyncEnumerable<double> source, CancellationToken cancellationToken)
  150. {
  151. if (source == null)
  152. throw new ArgumentNullException(nameof(source));
  153. return source.Aggregate(new Func<double, double, double>(Math.Max), cancellationToken);
  154. }
  155. public static Task<double> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector)
  156. {
  157. if (source == null)
  158. throw new ArgumentNullException(nameof(source));
  159. if (selector == null)
  160. throw new ArgumentNullException(nameof(selector));
  161. return source.Select(selector).Max(CancellationToken.None);
  162. }
  163. public static Task<double> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
  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);
  170. }
  171. public static Task<double> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double>> selector)
  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.None);
  178. }
  179. public static Task<double> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double>> selector, CancellationToken cancellationToken)
  180. {
  181. if (source == null)
  182. throw new ArgumentNullException(nameof(source));
  183. if (selector == null)
  184. throw new ArgumentNullException(nameof(selector));
  185. return source.Select(selector).Max(cancellationToken);
  186. }
  187. public static Task<decimal> Max(this IAsyncEnumerable<decimal> source)
  188. {
  189. if (source == null)
  190. throw new ArgumentNullException(nameof(source));
  191. return source.Aggregate(new Func<decimal, decimal, decimal>(Math.Max), CancellationToken.None);
  192. }
  193. public static Task<decimal> Max(this IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
  194. {
  195. if (source == null)
  196. throw new ArgumentNullException(nameof(source));
  197. return source.Aggregate(new Func<decimal, decimal, decimal>(Math.Max), cancellationToken);
  198. }
  199. public static Task<decimal> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector)
  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.None);
  206. }
  207. public static Task<decimal> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
  208. {
  209. if (source == null)
  210. throw new ArgumentNullException(nameof(source));
  211. if (selector == null)
  212. throw new ArgumentNullException(nameof(selector));
  213. return source.Select(selector).Max(cancellationToken);
  214. }
  215. public static Task<decimal> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal>> selector)
  216. {
  217. if (source == null)
  218. throw new ArgumentNullException(nameof(source));
  219. if (selector == null)
  220. throw new ArgumentNullException(nameof(selector));
  221. return source.Select(selector).Max(CancellationToken.None);
  222. }
  223. public static Task<decimal> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal>> selector, CancellationToken cancellationToken)
  224. {
  225. if (source == null)
  226. throw new ArgumentNullException(nameof(source));
  227. if (selector == null)
  228. throw new ArgumentNullException(nameof(selector));
  229. return source.Select(selector).Max(cancellationToken);
  230. }
  231. public static Task<int?> Max(this IAsyncEnumerable<int?> source)
  232. {
  233. if (source == null)
  234. throw new ArgumentNullException(nameof(source));
  235. return source.Aggregate(default(int?), new Func<int?, int?, int?>(NullableMax), CancellationToken.None);
  236. }
  237. public static Task<int?> Max(this IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
  238. {
  239. if (source == null)
  240. throw new ArgumentNullException(nameof(source));
  241. return source.Aggregate(default(int?), new Func<int?, int?, int?>(NullableMax), cancellationToken);
  242. }
  243. public static Task<int?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector)
  244. {
  245. if (source == null)
  246. throw new ArgumentNullException(nameof(source));
  247. if (selector == null)
  248. throw new ArgumentNullException(nameof(selector));
  249. return source.Select(selector).Max(CancellationToken.None);
  250. }
  251. public static Task<int?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
  252. {
  253. if (source == null)
  254. throw new ArgumentNullException(nameof(source));
  255. if (selector == null)
  256. throw new ArgumentNullException(nameof(selector));
  257. return source.Select(selector).Max(cancellationToken);
  258. }
  259. public static Task<int?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int?>> selector)
  260. {
  261. if (source == null)
  262. throw new ArgumentNullException(nameof(source));
  263. if (selector == null)
  264. throw new ArgumentNullException(nameof(selector));
  265. return source.Select(selector).Max(CancellationToken.None);
  266. }
  267. public static Task<int?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int?>> selector, CancellationToken cancellationToken)
  268. {
  269. if (source == null)
  270. throw new ArgumentNullException(nameof(source));
  271. if (selector == null)
  272. throw new ArgumentNullException(nameof(selector));
  273. return source.Select(selector).Max(cancellationToken);
  274. }
  275. public static Task<long?> Max(this IAsyncEnumerable<long?> source)
  276. {
  277. if (source == null)
  278. throw new ArgumentNullException(nameof(source));
  279. return source.Aggregate(default(long?), new Func<long?, long?, long?>(NullableMax), CancellationToken.None);
  280. }
  281. public static Task<long?> Max(this IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
  282. {
  283. if (source == null)
  284. throw new ArgumentNullException(nameof(source));
  285. return source.Aggregate(default(long?), new Func<long?, long?, long?>(NullableMax), cancellationToken);
  286. }
  287. public static Task<long?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector)
  288. {
  289. if (source == null)
  290. throw new ArgumentNullException(nameof(source));
  291. if (selector == null)
  292. throw new ArgumentNullException(nameof(selector));
  293. return source.Select(selector).Max(CancellationToken.None);
  294. }
  295. public static Task<long?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
  296. {
  297. if (source == null)
  298. throw new ArgumentNullException(nameof(source));
  299. if (selector == null)
  300. throw new ArgumentNullException(nameof(selector));
  301. return source.Select(selector).Max(cancellationToken);
  302. }
  303. public static Task<long?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long?>> 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).Max(CancellationToken.None);
  310. }
  311. public static Task<long?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long?>> 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).Max(cancellationToken);
  318. }
  319. public static Task<float?> Max(this IAsyncEnumerable<float?> source)
  320. {
  321. if (source == null)
  322. throw new ArgumentNullException(nameof(source));
  323. return source.Aggregate(default(float?), new Func<float?, float?, float?>(NullableMax), CancellationToken.None);
  324. }
  325. public static Task<float?> Max(this IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
  326. {
  327. if (source == null)
  328. throw new ArgumentNullException(nameof(source));
  329. return source.Aggregate(default(float?), new Func<float?, float?, float?>(NullableMax), cancellationToken);
  330. }
  331. public static Task<float?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> 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).Max(CancellationToken.None);
  338. }
  339. public static Task<float?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> 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).Max(cancellationToken);
  346. }
  347. public static Task<float?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float?>> selector)
  348. {
  349. if (source == null)
  350. throw new ArgumentNullException(nameof(source));
  351. if (selector == null)
  352. throw new ArgumentNullException(nameof(selector));
  353. return source.Select(selector).Max(CancellationToken.None);
  354. }
  355. public static Task<float?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float?>> selector, CancellationToken cancellationToken)
  356. {
  357. if (source == null)
  358. throw new ArgumentNullException(nameof(source));
  359. if (selector == null)
  360. throw new ArgumentNullException(nameof(selector));
  361. return source.Select(selector).Max(cancellationToken);
  362. }
  363. public static Task<double?> Max(this IAsyncEnumerable<double?> source)
  364. {
  365. if (source == null)
  366. throw new ArgumentNullException(nameof(source));
  367. return source.Aggregate(default(double?), new Func<double?, double?, double?>(NullableMax), CancellationToken.None);
  368. }
  369. public static Task<double?> Max(this IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
  370. {
  371. if (source == null)
  372. throw new ArgumentNullException(nameof(source));
  373. return source.Aggregate(default(double?), new Func<double?, double?, double?>(NullableMax), cancellationToken);
  374. }
  375. public static Task<double?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector)
  376. {
  377. if (source == null)
  378. throw new ArgumentNullException(nameof(source));
  379. if (selector == null)
  380. throw new ArgumentNullException(nameof(selector));
  381. return source.Select(selector).Max(CancellationToken.None);
  382. }
  383. public static Task<double?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
  384. {
  385. if (source == null)
  386. throw new ArgumentNullException(nameof(source));
  387. if (selector == null)
  388. throw new ArgumentNullException(nameof(selector));
  389. return source.Select(selector).Max(cancellationToken);
  390. }
  391. public static Task<double?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double?>> selector)
  392. {
  393. if (source == null)
  394. throw new ArgumentNullException(nameof(source));
  395. if (selector == null)
  396. throw new ArgumentNullException(nameof(selector));
  397. return source.Select(selector).Max(CancellationToken.None);
  398. }
  399. public static Task<double?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double?>> selector, CancellationToken cancellationToken)
  400. {
  401. if (source == null)
  402. throw new ArgumentNullException(nameof(source));
  403. if (selector == null)
  404. throw new ArgumentNullException(nameof(selector));
  405. return source.Select(selector).Max(cancellationToken);
  406. }
  407. public static Task<decimal?> Max(this IAsyncEnumerable<decimal?> source)
  408. {
  409. if (source == null)
  410. throw new ArgumentNullException(nameof(source));
  411. return source.Aggregate(default(decimal?), new Func<decimal?, decimal?, decimal?>(NullableMax), CancellationToken.None);
  412. }
  413. public static Task<decimal?> Max(this IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
  414. {
  415. if (source == null)
  416. throw new ArgumentNullException(nameof(source));
  417. return source.Aggregate(default(decimal?), new Func<decimal?, decimal?, decimal?>(NullableMax), cancellationToken);
  418. }
  419. public static Task<decimal?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector)
  420. {
  421. if (source == null)
  422. throw new ArgumentNullException(nameof(source));
  423. if (selector == null)
  424. throw new ArgumentNullException(nameof(selector));
  425. return source.Select(selector).Max(CancellationToken.None);
  426. }
  427. public static Task<decimal?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
  428. {
  429. if (source == null)
  430. throw new ArgumentNullException(nameof(source));
  431. if (selector == null)
  432. throw new ArgumentNullException(nameof(selector));
  433. return source.Select(selector).Max(cancellationToken);
  434. }
  435. public static Task<decimal?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal?>> selector)
  436. {
  437. if (source == null)
  438. throw new ArgumentNullException(nameof(source));
  439. if (selector == null)
  440. throw new ArgumentNullException(nameof(selector));
  441. return source.Select(selector).Max(CancellationToken.None);
  442. }
  443. public static Task<decimal?> Max<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal?>> selector, CancellationToken cancellationToken)
  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).Max(cancellationToken);
  450. }
  451. public static Task<int> Min(this IAsyncEnumerable<int> source)
  452. {
  453. if (source == null)
  454. throw new ArgumentNullException(nameof(source));
  455. return source.Aggregate(new Func<int, int, int>(Math.Min), CancellationToken.None);
  456. }
  457. public static Task<int> Min(this IAsyncEnumerable<int> source, CancellationToken cancellationToken)
  458. {
  459. if (source == null)
  460. throw new ArgumentNullException(nameof(source));
  461. return source.Aggregate(new Func<int, int, int>(Math.Min), cancellationToken);
  462. }
  463. public static Task<int> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector)
  464. {
  465. if (source == null)
  466. throw new ArgumentNullException(nameof(source));
  467. if (selector == null)
  468. throw new ArgumentNullException(nameof(selector));
  469. return source.Select(selector).Min(CancellationToken.None);
  470. }
  471. public static Task<int> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> selector, CancellationToken cancellationToken)
  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);
  478. }
  479. public static Task<int> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int>> selector)
  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.None);
  486. }
  487. public static Task<int> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int>> selector, CancellationToken cancellationToken)
  488. {
  489. if (source == null)
  490. throw new ArgumentNullException(nameof(source));
  491. if (selector == null)
  492. throw new ArgumentNullException(nameof(selector));
  493. return source.Select(selector).Min(cancellationToken);
  494. }
  495. public static Task<long> Min(this IAsyncEnumerable<long> source)
  496. {
  497. if (source == null)
  498. throw new ArgumentNullException(nameof(source));
  499. return source.Aggregate(new Func<long, long, long>(Math.Min), CancellationToken.None);
  500. }
  501. public static Task<long> Min(this IAsyncEnumerable<long> source, CancellationToken cancellationToken)
  502. {
  503. if (source == null)
  504. throw new ArgumentNullException(nameof(source));
  505. return source.Aggregate(new Func<long, long, long>(Math.Min), cancellationToken);
  506. }
  507. public static Task<long> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector)
  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.None);
  514. }
  515. public static Task<long> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken)
  516. {
  517. if (source == null)
  518. throw new ArgumentNullException(nameof(source));
  519. if (selector == null)
  520. throw new ArgumentNullException(nameof(selector));
  521. return source.Select(selector).Min(cancellationToken);
  522. }
  523. public static Task<long> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long>> selector)
  524. {
  525. if (source == null)
  526. throw new ArgumentNullException(nameof(source));
  527. if (selector == null)
  528. throw new ArgumentNullException(nameof(selector));
  529. return source.Select(selector).Min(CancellationToken.None);
  530. }
  531. public static Task<long> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long>> selector, CancellationToken cancellationToken)
  532. {
  533. if (source == null)
  534. throw new ArgumentNullException(nameof(source));
  535. if (selector == null)
  536. throw new ArgumentNullException(nameof(selector));
  537. return source.Select(selector).Min(cancellationToken);
  538. }
  539. public static Task<float> Min(this IAsyncEnumerable<float> source)
  540. {
  541. if (source == null)
  542. throw new ArgumentNullException(nameof(source));
  543. return source.Aggregate(new Func<float, float, float>(Math.Min), CancellationToken.None);
  544. }
  545. public static Task<float> Min(this IAsyncEnumerable<float> source, CancellationToken cancellationToken)
  546. {
  547. if (source == null)
  548. throw new ArgumentNullException(nameof(source));
  549. return source.Aggregate(new Func<float, float, float>(Math.Min), cancellationToken);
  550. }
  551. public static Task<float> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector)
  552. {
  553. if (source == null)
  554. throw new ArgumentNullException(nameof(source));
  555. if (selector == null)
  556. throw new ArgumentNullException(nameof(selector));
  557. return source.Select(selector).Min(CancellationToken.None);
  558. }
  559. public static Task<float> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken)
  560. {
  561. if (source == null)
  562. throw new ArgumentNullException(nameof(source));
  563. if (selector == null)
  564. throw new ArgumentNullException(nameof(selector));
  565. return source.Select(selector).Min(cancellationToken);
  566. }
  567. public static Task<float> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float>> selector)
  568. {
  569. if (source == null)
  570. throw new ArgumentNullException(nameof(source));
  571. if (selector == null)
  572. throw new ArgumentNullException(nameof(selector));
  573. return source.Select(selector).Min(CancellationToken.None);
  574. }
  575. public static Task<float> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float>> selector, CancellationToken cancellationToken)
  576. {
  577. if (source == null)
  578. throw new ArgumentNullException(nameof(source));
  579. if (selector == null)
  580. throw new ArgumentNullException(nameof(selector));
  581. return source.Select(selector).Min(cancellationToken);
  582. }
  583. public static Task<double> Min(this IAsyncEnumerable<double> source)
  584. {
  585. if (source == null)
  586. throw new ArgumentNullException(nameof(source));
  587. return source.Aggregate(new Func<double, double, double>(Math.Min), CancellationToken.None);
  588. }
  589. public static Task<double> Min(this IAsyncEnumerable<double> source, CancellationToken cancellationToken)
  590. {
  591. if (source == null)
  592. throw new ArgumentNullException(nameof(source));
  593. return source.Aggregate(new Func<double, double, double>(Math.Min), cancellationToken);
  594. }
  595. public static Task<double> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector)
  596. {
  597. if (source == null)
  598. throw new ArgumentNullException(nameof(source));
  599. if (selector == null)
  600. throw new ArgumentNullException(nameof(selector));
  601. return source.Select(selector).Min(CancellationToken.None);
  602. }
  603. public static Task<double> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken)
  604. {
  605. if (source == null)
  606. throw new ArgumentNullException(nameof(source));
  607. if (selector == null)
  608. throw new ArgumentNullException(nameof(selector));
  609. return source.Select(selector).Min(cancellationToken);
  610. }
  611. public static Task<double> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double>> selector)
  612. {
  613. if (source == null)
  614. throw new ArgumentNullException(nameof(source));
  615. if (selector == null)
  616. throw new ArgumentNullException(nameof(selector));
  617. return source.Select(selector).Min(CancellationToken.None);
  618. }
  619. public static Task<double> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double>> selector, CancellationToken cancellationToken)
  620. {
  621. if (source == null)
  622. throw new ArgumentNullException(nameof(source));
  623. if (selector == null)
  624. throw new ArgumentNullException(nameof(selector));
  625. return source.Select(selector).Min(cancellationToken);
  626. }
  627. public static Task<decimal> Min(this IAsyncEnumerable<decimal> source)
  628. {
  629. if (source == null)
  630. throw new ArgumentNullException(nameof(source));
  631. return source.Aggregate(new Func<decimal, decimal, decimal>(Math.Min), CancellationToken.None);
  632. }
  633. public static Task<decimal> Min(this IAsyncEnumerable<decimal> source, CancellationToken cancellationToken)
  634. {
  635. if (source == null)
  636. throw new ArgumentNullException(nameof(source));
  637. return source.Aggregate(new Func<decimal, decimal, decimal>(Math.Min), cancellationToken);
  638. }
  639. public static Task<decimal> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector)
  640. {
  641. if (source == null)
  642. throw new ArgumentNullException(nameof(source));
  643. if (selector == null)
  644. throw new ArgumentNullException(nameof(selector));
  645. return source.Select(selector).Min(CancellationToken.None);
  646. }
  647. public static Task<decimal> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken)
  648. {
  649. if (source == null)
  650. throw new ArgumentNullException(nameof(source));
  651. if (selector == null)
  652. throw new ArgumentNullException(nameof(selector));
  653. return source.Select(selector).Min(cancellationToken);
  654. }
  655. public static Task<decimal> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal>> selector)
  656. {
  657. if (source == null)
  658. throw new ArgumentNullException(nameof(source));
  659. if (selector == null)
  660. throw new ArgumentNullException(nameof(selector));
  661. return source.Select(selector).Min(CancellationToken.None);
  662. }
  663. public static Task<decimal> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal>> selector, CancellationToken cancellationToken)
  664. {
  665. if (source == null)
  666. throw new ArgumentNullException(nameof(source));
  667. if (selector == null)
  668. throw new ArgumentNullException(nameof(selector));
  669. return source.Select(selector).Min(cancellationToken);
  670. }
  671. public static Task<int?> Min(this IAsyncEnumerable<int?> source)
  672. {
  673. if (source == null)
  674. throw new ArgumentNullException(nameof(source));
  675. return source.Aggregate(default(int?), new Func<int?, int?, int?>(NullableMin), CancellationToken.None);
  676. }
  677. public static Task<int?> Min(this IAsyncEnumerable<int?> source, CancellationToken cancellationToken)
  678. {
  679. if (source == null)
  680. throw new ArgumentNullException(nameof(source));
  681. return source.Aggregate(default(int?), new Func<int?, int?, int?>(NullableMin), cancellationToken);
  682. }
  683. public static Task<int?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector)
  684. {
  685. if (source == null)
  686. throw new ArgumentNullException(nameof(source));
  687. if (selector == null)
  688. throw new ArgumentNullException(nameof(selector));
  689. return source.Select(selector).Min(CancellationToken.None);
  690. }
  691. public static Task<int?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken)
  692. {
  693. if (source == null)
  694. throw new ArgumentNullException(nameof(source));
  695. if (selector == null)
  696. throw new ArgumentNullException(nameof(selector));
  697. return source.Select(selector).Min(cancellationToken);
  698. }
  699. public static Task<int?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int?>> selector)
  700. {
  701. if (source == null)
  702. throw new ArgumentNullException(nameof(source));
  703. if (selector == null)
  704. throw new ArgumentNullException(nameof(selector));
  705. return source.Select(selector).Min(CancellationToken.None);
  706. }
  707. public static Task<int?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<int?>> selector, CancellationToken cancellationToken)
  708. {
  709. if (source == null)
  710. throw new ArgumentNullException(nameof(source));
  711. if (selector == null)
  712. throw new ArgumentNullException(nameof(selector));
  713. return source.Select(selector).Min(cancellationToken);
  714. }
  715. public static Task<long?> Min(this IAsyncEnumerable<long?> source)
  716. {
  717. if (source == null)
  718. throw new ArgumentNullException(nameof(source));
  719. return source.Aggregate(default(long?), new Func<long?, long?, long?>(NullableMin), CancellationToken.None);
  720. }
  721. public static Task<long?> Min(this IAsyncEnumerable<long?> source, CancellationToken cancellationToken)
  722. {
  723. if (source == null)
  724. throw new ArgumentNullException(nameof(source));
  725. return source.Aggregate(default(long?), new Func<long?, long?, long?>(NullableMin), cancellationToken);
  726. }
  727. public static Task<long?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector)
  728. {
  729. if (source == null)
  730. throw new ArgumentNullException(nameof(source));
  731. if (selector == null)
  732. throw new ArgumentNullException(nameof(selector));
  733. return source.Select(selector).Min(CancellationToken.None);
  734. }
  735. public static Task<long?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken)
  736. {
  737. if (source == null)
  738. throw new ArgumentNullException(nameof(source));
  739. if (selector == null)
  740. throw new ArgumentNullException(nameof(selector));
  741. return source.Select(selector).Min(cancellationToken);
  742. }
  743. public static Task<long?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long?>> selector)
  744. {
  745. if (source == null)
  746. throw new ArgumentNullException(nameof(source));
  747. if (selector == null)
  748. throw new ArgumentNullException(nameof(selector));
  749. return source.Select(selector).Min(CancellationToken.None);
  750. }
  751. public static Task<long?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<long?>> selector, CancellationToken cancellationToken)
  752. {
  753. if (source == null)
  754. throw new ArgumentNullException(nameof(source));
  755. if (selector == null)
  756. throw new ArgumentNullException(nameof(selector));
  757. return source.Select(selector).Min(cancellationToken);
  758. }
  759. public static Task<float?> Min(this IAsyncEnumerable<float?> source)
  760. {
  761. if (source == null)
  762. throw new ArgumentNullException(nameof(source));
  763. return source.Aggregate(default(float?), new Func<float?, float?, float?>(NullableMin), CancellationToken.None);
  764. }
  765. public static Task<float?> Min(this IAsyncEnumerable<float?> source, CancellationToken cancellationToken)
  766. {
  767. if (source == null)
  768. throw new ArgumentNullException(nameof(source));
  769. return source.Aggregate(default(float?), new Func<float?, float?, float?>(NullableMin), cancellationToken);
  770. }
  771. public static Task<float?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector)
  772. {
  773. if (source == null)
  774. throw new ArgumentNullException(nameof(source));
  775. if (selector == null)
  776. throw new ArgumentNullException(nameof(selector));
  777. return source.Select(selector).Min(CancellationToken.None);
  778. }
  779. public static Task<float?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken)
  780. {
  781. if (source == null)
  782. throw new ArgumentNullException(nameof(source));
  783. if (selector == null)
  784. throw new ArgumentNullException(nameof(selector));
  785. return source.Select(selector).Min(cancellationToken);
  786. }
  787. public static Task<float?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float?>> selector)
  788. {
  789. if (source == null)
  790. throw new ArgumentNullException(nameof(source));
  791. if (selector == null)
  792. throw new ArgumentNullException(nameof(selector));
  793. return source.Select(selector).Min(CancellationToken.None);
  794. }
  795. public static Task<float?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<float?>> selector, CancellationToken cancellationToken)
  796. {
  797. if (source == null)
  798. throw new ArgumentNullException(nameof(source));
  799. if (selector == null)
  800. throw new ArgumentNullException(nameof(selector));
  801. return source.Select(selector).Min(cancellationToken);
  802. }
  803. public static Task<double?> Min(this IAsyncEnumerable<double?> source)
  804. {
  805. if (source == null)
  806. throw new ArgumentNullException(nameof(source));
  807. return source.Aggregate(default(double?), new Func<double?, double?, double?>(NullableMin), CancellationToken.None);
  808. }
  809. public static Task<double?> Min(this IAsyncEnumerable<double?> source, CancellationToken cancellationToken)
  810. {
  811. if (source == null)
  812. throw new ArgumentNullException(nameof(source));
  813. return source.Aggregate(default(double?), new Func<double?, double?, double?>(NullableMin), cancellationToken);
  814. }
  815. public static Task<double?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector)
  816. {
  817. if (source == null)
  818. throw new ArgumentNullException(nameof(source));
  819. if (selector == null)
  820. throw new ArgumentNullException(nameof(selector));
  821. return source.Select(selector).Min(CancellationToken.None);
  822. }
  823. public static Task<double?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken)
  824. {
  825. if (source == null)
  826. throw new ArgumentNullException(nameof(source));
  827. if (selector == null)
  828. throw new ArgumentNullException(nameof(selector));
  829. return source.Select(selector).Min(cancellationToken);
  830. }
  831. public static Task<double?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double?>> selector)
  832. {
  833. if (source == null)
  834. throw new ArgumentNullException(nameof(source));
  835. if (selector == null)
  836. throw new ArgumentNullException(nameof(selector));
  837. return source.Select(selector).Min(CancellationToken.None);
  838. }
  839. public static Task<double?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<double?>> selector, CancellationToken cancellationToken)
  840. {
  841. if (source == null)
  842. throw new ArgumentNullException(nameof(source));
  843. if (selector == null)
  844. throw new ArgumentNullException(nameof(selector));
  845. return source.Select(selector).Min(cancellationToken);
  846. }
  847. public static Task<decimal?> Min(this IAsyncEnumerable<decimal?> source)
  848. {
  849. if (source == null)
  850. throw new ArgumentNullException(nameof(source));
  851. return source.Aggregate(default(decimal?), new Func<decimal?, decimal?, decimal?>(NullableMin), CancellationToken.None);
  852. }
  853. public static Task<decimal?> Min(this IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken)
  854. {
  855. if (source == null)
  856. throw new ArgumentNullException(nameof(source));
  857. return source.Aggregate(default(decimal?), new Func<decimal?, decimal?, decimal?>(NullableMin), cancellationToken);
  858. }
  859. public static Task<decimal?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector)
  860. {
  861. if (source == null)
  862. throw new ArgumentNullException(nameof(source));
  863. if (selector == null)
  864. throw new ArgumentNullException(nameof(selector));
  865. return source.Select(selector).Min(CancellationToken.None);
  866. }
  867. public static Task<decimal?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken)
  868. {
  869. if (source == null)
  870. throw new ArgumentNullException(nameof(source));
  871. if (selector == null)
  872. throw new ArgumentNullException(nameof(selector));
  873. return source.Select(selector).Min(cancellationToken);
  874. }
  875. public static Task<decimal?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal?>> selector)
  876. {
  877. if (source == null)
  878. throw new ArgumentNullException(nameof(source));
  879. if (selector == null)
  880. throw new ArgumentNullException(nameof(selector));
  881. return source.Select(selector).Min(CancellationToken.None);
  882. }
  883. public static Task<decimal?> Min<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, Task<decimal?>> selector, CancellationToken cancellationToken)
  884. {
  885. if (source == null)
  886. throw new ArgumentNullException(nameof(source));
  887. if (selector == null)
  888. throw new ArgumentNullException(nameof(selector));
  889. return source.Select(selector).Min(cancellationToken);
  890. }
  891. private static T? NullableMax<T>(T? x, T? y)
  892. where T : struct, IComparable<T>
  893. {
  894. if (!x.HasValue)
  895. return y;
  896. if (!y.HasValue)
  897. return x;
  898. if (x.Value.CompareTo(y.Value) >= 0)
  899. return x;
  900. return y;
  901. }
  902. private static T? NullableMin<T>(T? x, T? y)
  903. where T : struct, IComparable<T>
  904. {
  905. if (!x.HasValue)
  906. return y;
  907. if (!y.HasValue)
  908. return x;
  909. if (x.Value.CompareTo(y.Value) <= 0)
  910. return x;
  911. return y;
  912. }
  913. }
  914. }