Average.Generated.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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<double> AverageAsync(this IAsyncEnumerable<int> source, CancellationToken cancellationToken = default)
  12. {
  13. if (source == null)
  14. throw Error.ArgumentNull(nameof(source));
  15. return AverageCore(source, cancellationToken);
  16. }
  17. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int> 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 AverageCore(source, selector, cancellationToken);
  24. }
  25. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<int>> 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 AverageCore(source, selector, cancellationToken);
  32. }
  33. #if !NO_DEEP_CANCELLATION
  34. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<int>> 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 AverageCore(source, selector, cancellationToken);
  41. }
  42. #endif
  43. public static Task<double> AverageAsync(this IAsyncEnumerable<long> source, CancellationToken cancellationToken = default)
  44. {
  45. if (source == null)
  46. throw Error.ArgumentNull(nameof(source));
  47. return AverageCore(source, cancellationToken);
  48. }
  49. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long> selector, CancellationToken cancellationToken = default)
  50. {
  51. if (source == null)
  52. throw Error.ArgumentNull(nameof(source));
  53. if (selector == null)
  54. throw Error.ArgumentNull(nameof(selector));
  55. return AverageCore(source, selector, cancellationToken);
  56. }
  57. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<long>> selector, CancellationToken cancellationToken = default)
  58. {
  59. if (source == null)
  60. throw Error.ArgumentNull(nameof(source));
  61. if (selector == null)
  62. throw Error.ArgumentNull(nameof(selector));
  63. return AverageCore(source, selector, cancellationToken);
  64. }
  65. #if !NO_DEEP_CANCELLATION
  66. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<long>> selector, CancellationToken cancellationToken = default)
  67. {
  68. if (source == null)
  69. throw Error.ArgumentNull(nameof(source));
  70. if (selector == null)
  71. throw Error.ArgumentNull(nameof(selector));
  72. return AverageCore(source, selector, cancellationToken);
  73. }
  74. #endif
  75. public static Task<float> AverageAsync(this IAsyncEnumerable<float> source, CancellationToken cancellationToken = default)
  76. {
  77. if (source == null)
  78. throw Error.ArgumentNull(nameof(source));
  79. return AverageCore(source, cancellationToken);
  80. }
  81. public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float> selector, CancellationToken cancellationToken = default)
  82. {
  83. if (source == null)
  84. throw Error.ArgumentNull(nameof(source));
  85. if (selector == null)
  86. throw Error.ArgumentNull(nameof(selector));
  87. return AverageCore(source, selector, cancellationToken);
  88. }
  89. public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<float>> selector, CancellationToken cancellationToken = default)
  90. {
  91. if (source == null)
  92. throw Error.ArgumentNull(nameof(source));
  93. if (selector == null)
  94. throw Error.ArgumentNull(nameof(selector));
  95. return AverageCore(source, selector, cancellationToken);
  96. }
  97. #if !NO_DEEP_CANCELLATION
  98. public static Task<float> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<float>> selector, CancellationToken cancellationToken = default)
  99. {
  100. if (source == null)
  101. throw Error.ArgumentNull(nameof(source));
  102. if (selector == null)
  103. throw Error.ArgumentNull(nameof(selector));
  104. return AverageCore(source, selector, cancellationToken);
  105. }
  106. #endif
  107. public static Task<double> AverageAsync(this IAsyncEnumerable<double> source, CancellationToken cancellationToken = default)
  108. {
  109. if (source == null)
  110. throw Error.ArgumentNull(nameof(source));
  111. return AverageCore(source, cancellationToken);
  112. }
  113. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double> selector, CancellationToken cancellationToken = default)
  114. {
  115. if (source == null)
  116. throw Error.ArgumentNull(nameof(source));
  117. if (selector == null)
  118. throw Error.ArgumentNull(nameof(selector));
  119. return AverageCore(source, selector, cancellationToken);
  120. }
  121. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<double>> selector, CancellationToken cancellationToken = default)
  122. {
  123. if (source == null)
  124. throw Error.ArgumentNull(nameof(source));
  125. if (selector == null)
  126. throw Error.ArgumentNull(nameof(selector));
  127. return AverageCore(source, selector, cancellationToken);
  128. }
  129. #if !NO_DEEP_CANCELLATION
  130. public static Task<double> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<double>> selector, CancellationToken cancellationToken = default)
  131. {
  132. if (source == null)
  133. throw Error.ArgumentNull(nameof(source));
  134. if (selector == null)
  135. throw Error.ArgumentNull(nameof(selector));
  136. return AverageCore(source, selector, cancellationToken);
  137. }
  138. #endif
  139. public static Task<decimal> AverageAsync(this IAsyncEnumerable<decimal> source, CancellationToken cancellationToken = default)
  140. {
  141. if (source == null)
  142. throw Error.ArgumentNull(nameof(source));
  143. return AverageCore(source, cancellationToken);
  144. }
  145. public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal> selector, CancellationToken cancellationToken = default)
  146. {
  147. if (source == null)
  148. throw Error.ArgumentNull(nameof(source));
  149. if (selector == null)
  150. throw Error.ArgumentNull(nameof(selector));
  151. return AverageCore(source, selector, cancellationToken);
  152. }
  153. public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<decimal>> selector, CancellationToken cancellationToken = default)
  154. {
  155. if (source == null)
  156. throw Error.ArgumentNull(nameof(source));
  157. if (selector == null)
  158. throw Error.ArgumentNull(nameof(selector));
  159. return AverageCore(source, selector, cancellationToken);
  160. }
  161. #if !NO_DEEP_CANCELLATION
  162. public static Task<decimal> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<decimal>> selector, CancellationToken cancellationToken = default)
  163. {
  164. if (source == null)
  165. throw Error.ArgumentNull(nameof(source));
  166. if (selector == null)
  167. throw Error.ArgumentNull(nameof(selector));
  168. return AverageCore(source, selector, cancellationToken);
  169. }
  170. #endif
  171. public static Task<double?> AverageAsync(this IAsyncEnumerable<int?> source, CancellationToken cancellationToken = default)
  172. {
  173. if (source == null)
  174. throw Error.ArgumentNull(nameof(source));
  175. return AverageCore(source, cancellationToken);
  176. }
  177. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, int?> selector, CancellationToken cancellationToken = default)
  178. {
  179. if (source == null)
  180. throw Error.ArgumentNull(nameof(source));
  181. if (selector == null)
  182. throw Error.ArgumentNull(nameof(selector));
  183. return AverageCore(source, selector, cancellationToken);
  184. }
  185. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<int?>> selector, CancellationToken cancellationToken = default)
  186. {
  187. if (source == null)
  188. throw Error.ArgumentNull(nameof(source));
  189. if (selector == null)
  190. throw Error.ArgumentNull(nameof(selector));
  191. return AverageCore(source, selector, cancellationToken);
  192. }
  193. #if !NO_DEEP_CANCELLATION
  194. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<int?>> selector, CancellationToken cancellationToken = default)
  195. {
  196. if (source == null)
  197. throw Error.ArgumentNull(nameof(source));
  198. if (selector == null)
  199. throw Error.ArgumentNull(nameof(selector));
  200. return AverageCore(source, selector, cancellationToken);
  201. }
  202. #endif
  203. public static Task<double?> AverageAsync(this IAsyncEnumerable<long?> source, CancellationToken cancellationToken = default)
  204. {
  205. if (source == null)
  206. throw Error.ArgumentNull(nameof(source));
  207. return AverageCore(source, cancellationToken);
  208. }
  209. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long?> selector, CancellationToken cancellationToken = default)
  210. {
  211. if (source == null)
  212. throw Error.ArgumentNull(nameof(source));
  213. if (selector == null)
  214. throw Error.ArgumentNull(nameof(selector));
  215. return AverageCore(source, selector, cancellationToken);
  216. }
  217. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<long?>> selector, CancellationToken cancellationToken = default)
  218. {
  219. if (source == null)
  220. throw Error.ArgumentNull(nameof(source));
  221. if (selector == null)
  222. throw Error.ArgumentNull(nameof(selector));
  223. return AverageCore(source, selector, cancellationToken);
  224. }
  225. #if !NO_DEEP_CANCELLATION
  226. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<long?>> selector, CancellationToken cancellationToken = default)
  227. {
  228. if (source == null)
  229. throw Error.ArgumentNull(nameof(source));
  230. if (selector == null)
  231. throw Error.ArgumentNull(nameof(selector));
  232. return AverageCore(source, selector, cancellationToken);
  233. }
  234. #endif
  235. public static Task<float?> AverageAsync(this IAsyncEnumerable<float?> source, CancellationToken cancellationToken = default)
  236. {
  237. if (source == null)
  238. throw Error.ArgumentNull(nameof(source));
  239. return AverageCore(source, cancellationToken);
  240. }
  241. public static Task<float?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, float?> selector, CancellationToken cancellationToken = default)
  242. {
  243. if (source == null)
  244. throw Error.ArgumentNull(nameof(source));
  245. if (selector == null)
  246. throw Error.ArgumentNull(nameof(selector));
  247. return AverageCore(source, selector, cancellationToken);
  248. }
  249. public static Task<float?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<float?>> selector, CancellationToken cancellationToken = default)
  250. {
  251. if (source == null)
  252. throw Error.ArgumentNull(nameof(source));
  253. if (selector == null)
  254. throw Error.ArgumentNull(nameof(selector));
  255. return AverageCore(source, selector, cancellationToken);
  256. }
  257. #if !NO_DEEP_CANCELLATION
  258. public static Task<float?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<float?>> selector, CancellationToken cancellationToken = default)
  259. {
  260. if (source == null)
  261. throw Error.ArgumentNull(nameof(source));
  262. if (selector == null)
  263. throw Error.ArgumentNull(nameof(selector));
  264. return AverageCore(source, selector, cancellationToken);
  265. }
  266. #endif
  267. public static Task<double?> AverageAsync(this IAsyncEnumerable<double?> source, CancellationToken cancellationToken = default)
  268. {
  269. if (source == null)
  270. throw Error.ArgumentNull(nameof(source));
  271. return AverageCore(source, cancellationToken);
  272. }
  273. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, double?> selector, CancellationToken cancellationToken = default)
  274. {
  275. if (source == null)
  276. throw Error.ArgumentNull(nameof(source));
  277. if (selector == null)
  278. throw Error.ArgumentNull(nameof(selector));
  279. return AverageCore(source, selector, cancellationToken);
  280. }
  281. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<double?>> selector, CancellationToken cancellationToken = default)
  282. {
  283. if (source == null)
  284. throw Error.ArgumentNull(nameof(source));
  285. if (selector == null)
  286. throw Error.ArgumentNull(nameof(selector));
  287. return AverageCore(source, selector, cancellationToken);
  288. }
  289. #if !NO_DEEP_CANCELLATION
  290. public static Task<double?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<double?>> selector, CancellationToken cancellationToken = default)
  291. {
  292. if (source == null)
  293. throw Error.ArgumentNull(nameof(source));
  294. if (selector == null)
  295. throw Error.ArgumentNull(nameof(selector));
  296. return AverageCore(source, selector, cancellationToken);
  297. }
  298. #endif
  299. public static Task<decimal?> AverageAsync(this IAsyncEnumerable<decimal?> source, CancellationToken cancellationToken = default)
  300. {
  301. if (source == null)
  302. throw Error.ArgumentNull(nameof(source));
  303. return AverageCore(source, cancellationToken);
  304. }
  305. public static Task<decimal?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, decimal?> selector, CancellationToken cancellationToken = default)
  306. {
  307. if (source == null)
  308. throw Error.ArgumentNull(nameof(source));
  309. if (selector == null)
  310. throw Error.ArgumentNull(nameof(selector));
  311. return AverageCore(source, selector, cancellationToken);
  312. }
  313. public static Task<decimal?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<decimal?>> selector, CancellationToken cancellationToken = default)
  314. {
  315. if (source == null)
  316. throw Error.ArgumentNull(nameof(source));
  317. if (selector == null)
  318. throw Error.ArgumentNull(nameof(selector));
  319. return AverageCore(source, selector, cancellationToken);
  320. }
  321. #if !NO_DEEP_CANCELLATION
  322. public static Task<decimal?> AverageAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, CancellationToken, ValueTask<decimal?>> selector, CancellationToken cancellationToken = default)
  323. {
  324. if (source == null)
  325. throw Error.ArgumentNull(nameof(source));
  326. if (selector == null)
  327. throw Error.ArgumentNull(nameof(selector));
  328. return AverageCore(source, selector, cancellationToken);
  329. }
  330. #endif
  331. }
  332. }