Observable.Aggregates.cs 168 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace System.Reactive.Linq
  5. {
  6. public static partial class Observable
  7. {
  8. #region + Aggregate +
  9. /// <summary>
  10. /// Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
  11. /// For aggregation behavior with incremental intermediate results, see <see cref="Observable.Scan&lt;TSource, Accumulate&gt;"/>.
  12. /// </summary>
  13. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  14. /// <typeparam name="TAccumulate">The type of the result of the aggregation.</typeparam>
  15. /// <param name="source">An observable sequence to aggregate over.</param>
  16. /// <param name="seed">The initial accumulator value.</param>
  17. /// <param name="accumulator">An accumulator function to be invoked on each element.</param>
  18. /// <returns>An observable sequence containing a single element with the final accumulator value.</returns>
  19. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="accumulator"/> is null.</exception>
  20. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  21. public static IObservable<TAccumulate> Aggregate<TSource, TAccumulate>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator)
  22. {
  23. if (source == null)
  24. throw new ArgumentNullException("source");
  25. if (accumulator == null)
  26. throw new ArgumentNullException("accumulator");
  27. return s_impl.Aggregate<TSource, TAccumulate>(source, seed, accumulator);
  28. }
  29. /// <summary>
  30. /// Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value,
  31. /// and the specified result selector function is used to select the result value.
  32. /// </summary>
  33. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  34. /// <typeparam name="TAccumulate">The type of the accumulator value.</typeparam>
  35. /// <typeparam name="TResult">The type of the resulting value.</typeparam>
  36. /// <param name="source">An observable sequence to aggregate over.</param>
  37. /// <param name="seed">The initial accumulator value.</param>
  38. /// <param name="accumulator">An accumulator function to be invoked on each element.</param>
  39. /// <param name="resultSelector">A function to transform the final accumulator value into the result value.</param>
  40. /// <returns>An observable sequence containing a single element with the final accumulator value.</returns>
  41. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="accumulator"/> or <paramref name="resultSelector"/> is null.</exception>
  42. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  43. public static IObservable<TResult> Aggregate<TSource, TAccumulate, TResult>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator, Func<TAccumulate, TResult> resultSelector)
  44. {
  45. if (source == null)
  46. throw new ArgumentNullException("source");
  47. if (accumulator == null)
  48. throw new ArgumentNullException("accumulator");
  49. if (resultSelector == null)
  50. throw new ArgumentNullException("resultSelector");
  51. return s_impl.Aggregate<TSource, TAccumulate, TResult>(source, seed, accumulator, resultSelector);
  52. }
  53. /// <summary>
  54. /// Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence.
  55. /// For aggregation behavior with incremental intermediate results, see <see cref="Observable.Scan&lt;TSource&gt;"/>.
  56. /// </summary>
  57. /// <typeparam name="TSource">The type of the elements in the source sequence and the result of the aggregation.</typeparam>
  58. /// <param name="source">An observable sequence to aggregate over.</param>
  59. /// <param name="accumulator">An accumulator function to be invoked on each element.</param>
  60. /// <returns>An observable sequence containing a single element with the final accumulator value.</returns>
  61. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="accumulator"/> is null.</exception>
  62. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  63. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  64. public static IObservable<TSource> Aggregate<TSource>(this IObservable<TSource> source, Func<TSource, TSource, TSource> accumulator)
  65. {
  66. if (source == null)
  67. throw new ArgumentNullException("source");
  68. if (accumulator == null)
  69. throw new ArgumentNullException("accumulator");
  70. return s_impl.Aggregate<TSource>(source, accumulator);
  71. }
  72. #endregion
  73. #region + All +
  74. /// <summary>
  75. /// Determines whether all elements of an observable sequence satisfy a condition.
  76. /// </summary>
  77. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  78. /// <param name="source">An observable sequence whose elements to apply the predicate to.</param>
  79. /// <param name="predicate">A function to test each element for a condition.</param>
  80. /// <returns>An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.</returns>
  81. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  82. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  83. public static IObservable<bool> All<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  84. {
  85. if (source == null)
  86. throw new ArgumentNullException("source");
  87. if (predicate == null)
  88. throw new ArgumentNullException("predicate");
  89. return s_impl.All<TSource>(source, predicate);
  90. }
  91. #endregion
  92. #region + Any +
  93. /// <summary>
  94. /// Determines whether an observable sequence contains any elements.
  95. /// </summary>
  96. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  97. /// <param name="source">An observable sequence to check for non-emptiness.</param>
  98. /// <returns>An observable sequence containing a single element determining whether the source sequence contains any elements.</returns>
  99. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  100. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  101. public static IObservable<bool> Any<TSource>(this IObservable<TSource> source)
  102. {
  103. if (source == null)
  104. throw new ArgumentNullException("source");
  105. return s_impl.Any<TSource>(source);
  106. }
  107. /// <summary>
  108. /// Determines whether any element of an observable sequence satisfies a condition.
  109. /// </summary>
  110. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  111. /// <param name="source">An observable sequence whose elements to apply the predicate to.</param>
  112. /// <param name="predicate">A function to test each element for a condition.</param>
  113. /// <returns>An observable sequence containing a single element determining whether any elements in the source sequence pass the test in the specified predicate.</returns>
  114. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  115. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  116. public static IObservable<bool> Any<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  117. {
  118. if (source == null)
  119. throw new ArgumentNullException("source");
  120. if (predicate == null)
  121. throw new ArgumentNullException("predicate");
  122. return s_impl.Any<TSource>(source, predicate);
  123. }
  124. #endregion
  125. #region + Average +
  126. /// <summary>
  127. /// Computes the average of an observable sequence of <see cref="T:System.Double" /> values.
  128. /// </summary>
  129. /// <param name="source">A sequence of <see cref="T:System.Double" /> values to calculate the average of.</param>
  130. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  131. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  132. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  133. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  134. public static IObservable<double> Average(this IObservable<double> source)
  135. {
  136. if (source == null)
  137. throw new ArgumentNullException("source");
  138. return s_impl.Average(source);
  139. }
  140. /// <summary>
  141. /// Computes the average of an observable sequence of <see cref="T:System.Single" /> values.
  142. /// </summary>
  143. /// <param name="source">A sequence of <see cref="T:System.Single" /> values to calculate the average of.</param>
  144. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  145. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  146. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  147. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  148. public static IObservable<float> Average(this IObservable<float> source)
  149. {
  150. if (source == null)
  151. throw new ArgumentNullException("source");
  152. return s_impl.Average(source);
  153. }
  154. /// <summary>
  155. /// Computes the average of an observable sequence of <see cref="T:System.Decimal" /> values.
  156. /// </summary>
  157. /// <param name="source">A sequence of <see cref="T:System.Decimal" /> values to calculate the average of.</param>
  158. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  159. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  160. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  161. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Decimal.MaxValue"/>.</exception>
  162. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  163. public static IObservable<decimal> Average(this IObservable<decimal> source)
  164. {
  165. if (source == null)
  166. throw new ArgumentNullException("source");
  167. return s_impl.Average(source);
  168. }
  169. /// <summary>
  170. /// Computes the average of an observable sequence of <see cref="T:System.Int32" /> values.
  171. /// </summary>
  172. /// <param name="source">A sequence of <see cref="T:System.Int32" /> values to calculate the average of.</param>
  173. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  174. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  175. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  176. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  177. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  178. public static IObservable<double> Average(this IObservable<int> source)
  179. {
  180. if (source == null)
  181. throw new ArgumentNullException("source");
  182. return s_impl.Average(source);
  183. }
  184. /// <summary>
  185. /// Computes the average of an observable sequence of <see cref="T:System.Int64" /> values.
  186. /// </summary>
  187. /// <param name="source">A sequence of <see cref="T:System.Int64" /> values to calculate the average of.</param>
  188. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  189. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  190. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  191. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  192. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  193. public static IObservable<double> Average(this IObservable<long> source)
  194. {
  195. if (source == null)
  196. throw new ArgumentNullException("source");
  197. return s_impl.Average(source);
  198. }
  199. /// <summary>
  200. /// Computes the average of an observable sequence of nullable <see cref="T:System.Double" /> values.
  201. /// </summary>
  202. /// <param name="source">A sequence of nullable <see cref="T:System.Double" /> values to calculate the average of.</param>
  203. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  204. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  205. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  206. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  207. public static IObservable<double?> Average(this IObservable<double?> source)
  208. {
  209. if (source == null)
  210. throw new ArgumentNullException("source");
  211. return s_impl.Average(source);
  212. }
  213. /// <summary>
  214. /// Computes the average of an observable sequence of nullable <see cref="T:System.Single" /> values.
  215. /// </summary>
  216. /// <param name="source">A sequence of nullable <see cref="T:System.Single" /> values to calculate the average of.</param>
  217. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  218. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  219. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  220. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  221. public static IObservable<float?> Average(this IObservable<float?> source)
  222. {
  223. if (source == null)
  224. throw new ArgumentNullException("source");
  225. return s_impl.Average(source);
  226. }
  227. /// <summary>
  228. /// Computes the average of an observable sequence of nullable <see cref="T:System.Decimal" /> values.
  229. /// </summary>
  230. /// <param name="source">A sequence of nullable <see cref="T:System.Decimal" /> values to calculate the average of.</param>
  231. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  232. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  233. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  234. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Decimal.MaxValue"/>.</exception>
  235. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  236. public static IObservable<decimal?> Average(this IObservable<decimal?> source)
  237. {
  238. if (source == null)
  239. throw new ArgumentNullException("source");
  240. return s_impl.Average(source);
  241. }
  242. /// <summary>
  243. /// Computes the average of an observable sequence of nullable <see cref="T:System.Int32" /> values.
  244. /// </summary>
  245. /// <param name="source">A sequence of nullable <see cref="T:System.Int32" /> values to calculate the average of.</param>
  246. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  247. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  248. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  249. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  250. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  251. public static IObservable<double?> Average(this IObservable<int?> source)
  252. {
  253. if (source == null)
  254. throw new ArgumentNullException("source");
  255. return s_impl.Average(source);
  256. }
  257. /// <summary>
  258. /// Computes the average of an observable sequence of nullable <see cref="T:System.Int64" /> values.
  259. /// </summary>
  260. /// <param name="source">A sequence of nullable <see cref="T:System.Int64" /> values to calculate the average of.</param>
  261. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  262. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  263. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  264. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  265. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  266. public static IObservable<double?> Average(this IObservable<long?> source)
  267. {
  268. if (source == null)
  269. throw new ArgumentNullException("source");
  270. return s_impl.Average(source);
  271. }
  272. /// <summary>
  273. /// Computes the average of an observable sequence of <see cref="T:System.Decimal" /> values that are obtained by invoking a transform function on each element of the input sequence.
  274. /// </summary>
  275. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  276. /// <param name="source">A sequence of values to calculate the average of.</param>
  277. /// <param name="selector">A transform function to apply to each element.</param>
  278. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  279. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  280. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  281. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Decimal.MaxValue"/>.</exception>
  282. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  283. public static IObservable<decimal> Average<TSource>(this IObservable<TSource> source, Func<TSource, decimal> selector)
  284. {
  285. if (source == null)
  286. throw new ArgumentNullException("source");
  287. if (selector == null)
  288. throw new ArgumentNullException("selector");
  289. return s_impl.Average<TSource>(source, selector);
  290. }
  291. /// <summary>
  292. /// Computes the average of an observable sequence of <see cref="T:System.Double" /> values that are obtained by invoking a transform function on each element of the input sequence.
  293. /// </summary>
  294. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  295. /// <param name="source">A sequence of values to calculate the average of.</param>
  296. /// <param name="selector">A transform function to apply to each element.</param>
  297. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  298. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  299. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  300. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  301. public static IObservable<double> Average<TSource>(this IObservable<TSource> source, Func<TSource, double> selector)
  302. {
  303. if (source == null)
  304. throw new ArgumentNullException("source");
  305. if (selector == null)
  306. throw new ArgumentNullException("selector");
  307. return s_impl.Average<TSource>(source, selector);
  308. }
  309. /// <summary>
  310. /// Computes the average of an observable sequence of <see cref="T:System.Single" /> values that are obtained by invoking a transform function on each element of the input sequence.
  311. /// </summary>
  312. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  313. /// <param name="source">A sequence of values to calculate the average of.</param>
  314. /// <param name="selector">A transform function to apply to each element.</param>
  315. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  316. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  317. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  318. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  319. public static IObservable<float> Average<TSource>(this IObservable<TSource> source, Func<TSource, float> selector)
  320. {
  321. if (source == null)
  322. throw new ArgumentNullException("source");
  323. if (selector == null)
  324. throw new ArgumentNullException("selector");
  325. return s_impl.Average<TSource>(source, selector);
  326. }
  327. /// <summary>
  328. /// Computes the average of an observable sequence of <see cref="T:System.Int32" /> values that are obtained by invoking a transform function on each element of the input sequence.
  329. /// </summary>
  330. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  331. /// <param name="source">A sequence of values to calculate the average of.</param>
  332. /// <param name="selector">A transform function to apply to each element.</param>
  333. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  334. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  335. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  336. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  337. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  338. public static IObservable<double> Average<TSource>(this IObservable<TSource> source, Func<TSource, int> selector)
  339. {
  340. if (source == null)
  341. throw new ArgumentNullException("source");
  342. if (selector == null)
  343. throw new ArgumentNullException("selector");
  344. return s_impl.Average<TSource>(source, selector);
  345. }
  346. /// <summary>
  347. /// Computes the average of an observable sequence of <see cref="T:System.Int64" /> values that are obtained by invoking a transform function on each element of the input sequence.
  348. /// </summary>
  349. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  350. /// <param name="source">A sequence of values to calculate the average of.</param>
  351. /// <param name="selector">A transform function to apply to each element.</param>
  352. /// <returns>An observable sequence containing a single element with the average of the sequence of values.</returns>
  353. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  354. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  355. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  356. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  357. public static IObservable<double> Average<TSource>(this IObservable<TSource> source, Func<TSource, long> selector)
  358. {
  359. if (source == null)
  360. throw new ArgumentNullException("source");
  361. if (selector == null)
  362. throw new ArgumentNullException("selector");
  363. return s_impl.Average<TSource>(source, selector);
  364. }
  365. /// <summary>
  366. /// Computes the average of an observable sequence of nullable <see cref="T:System.Decimal" /> values that are obtained by invoking a transform function on each element of the input sequence.
  367. /// </summary>
  368. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  369. /// <param name="source">A sequence of values to calculate the average of.</param>
  370. /// <param name="selector">A transform function to apply to each element.</param>
  371. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  372. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  373. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  374. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Decimal.MaxValue"/>.</exception>
  375. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  376. public static IObservable<decimal?> Average<TSource>(this IObservable<TSource> source, Func<TSource, decimal?> selector)
  377. {
  378. if (source == null)
  379. throw new ArgumentNullException("source");
  380. if (selector == null)
  381. throw new ArgumentNullException("selector");
  382. return s_impl.Average<TSource>(source, selector);
  383. }
  384. /// <summary>
  385. /// Computes the average of an observable sequence of nullable <see cref="T:System.Double" /> values that are obtained by invoking a transform function on each element of the input sequence.
  386. /// </summary>
  387. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  388. /// <param name="source">A sequence of values to calculate the average of.</param>
  389. /// <param name="selector">A transform function to apply to each element.</param>
  390. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  391. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  392. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  393. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  394. public static IObservable<double?> Average<TSource>(this IObservable<TSource> source, Func<TSource, double?> selector)
  395. {
  396. if (source == null)
  397. throw new ArgumentNullException("source");
  398. if (selector == null)
  399. throw new ArgumentNullException("selector");
  400. return s_impl.Average<TSource>(source, selector);
  401. }
  402. /// <summary>
  403. /// Computes the average of an observable sequence of nullable <see cref="T:System.Single" /> values that are obtained by invoking a transform function on each element of the input sequence.
  404. /// </summary>
  405. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  406. /// <param name="source">A sequence of values to calculate the average of.</param>
  407. /// <param name="selector">A transform function to apply to each element.</param>
  408. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  409. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  410. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  411. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  412. public static IObservable<float?> Average<TSource>(this IObservable<TSource> source, Func<TSource, float?> selector)
  413. {
  414. if (source == null)
  415. throw new ArgumentNullException("source");
  416. if (selector == null)
  417. throw new ArgumentNullException("selector");
  418. return s_impl.Average<TSource>(source, selector);
  419. }
  420. /// <summary>
  421. /// Computes the average of an observable sequence of nullable <see cref="T:System.Int32" /> values that are obtained by invoking a transform function on each element of the input sequence.
  422. /// </summary>
  423. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  424. /// <param name="source">A sequence of values to calculate the average of.</param>
  425. /// <param name="selector">A transform function to apply to each element.</param>
  426. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  427. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  428. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  429. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  430. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  431. public static IObservable<double?> Average<TSource>(this IObservable<TSource> source, Func<TSource, int?> selector)
  432. {
  433. if (source == null)
  434. throw new ArgumentNullException("source");
  435. if (selector == null)
  436. throw new ArgumentNullException("selector");
  437. return s_impl.Average<TSource>(source, selector);
  438. }
  439. /// <summary>
  440. /// Computes the average of an observable sequence of nullable <see cref="T:System.Int64" /> values that are obtained by invoking a transform function on each element of the input sequence.
  441. /// </summary>
  442. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  443. /// <param name="source">A sequence of values to calculate the average of.</param>
  444. /// <param name="selector">A transform function to apply to each element.</param>
  445. /// <returns>An observable sequence containing a single element with the average of the sequence of values, or null if the source sequence is empty or contains only values that are null.</returns>
  446. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  447. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  448. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  449. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  450. public static IObservable<double?> Average<TSource>(this IObservable<TSource> source, Func<TSource, long?> selector)
  451. {
  452. if (source == null)
  453. throw new ArgumentNullException("source");
  454. if (selector == null)
  455. throw new ArgumentNullException("selector");
  456. return s_impl.Average<TSource>(source, selector);
  457. }
  458. #endregion
  459. #region + Contains +
  460. /// <summary>
  461. /// Determines whether an observable sequence contains a specified element by using the default equality comparer.
  462. /// </summary>
  463. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  464. /// <param name="source">An observable sequence in which to locate a value.</param>
  465. /// <param name="value">The value to locate in the source sequence.</param>
  466. /// <returns>An observable sequence containing a single element determining whether the source sequence contains an element that has the specified value.</returns>
  467. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  468. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  469. public static IObservable<bool> Contains<TSource>(this IObservable<TSource> source, TSource value)
  470. {
  471. if (source == null)
  472. throw new ArgumentNullException("source");
  473. return s_impl.Contains<TSource>(source, value);
  474. }
  475. /// <summary>
  476. /// Determines whether an observable sequence contains a specified element by using a specified System.Collections.Generic.IEqualityComparer&lt;T&gt;.
  477. /// </summary>
  478. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  479. /// <param name="source">An observable sequence in which to locate a value.</param>
  480. /// <param name="value">The value to locate in the source sequence.</param>
  481. /// <param name="comparer">An equality comparer to compare elements.</param>
  482. /// <returns>An observable sequence containing a single element determining whether the source sequence contains an element that has the specified value.</returns>
  483. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="comparer"/> is null.</exception>
  484. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  485. public static IObservable<bool> Contains<TSource>(this IObservable<TSource> source, TSource value, IEqualityComparer<TSource> comparer)
  486. {
  487. if (source == null)
  488. throw new ArgumentNullException("source");
  489. if (comparer == null)
  490. throw new ArgumentNullException("comparer");
  491. return s_impl.Contains<TSource>(source, value, comparer);
  492. }
  493. #endregion
  494. #region + Count +
  495. /// <summary>
  496. /// Returns an observable sequence containing an <see cref="T:System.Int32" /> that represents the total number of elements in an observable sequence.
  497. /// </summary>
  498. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  499. /// <param name="source">An observable sequence that contains elements to be counted.</param>
  500. /// <returns>An observable sequence containing a single element with the number of elements in the input sequence.</returns>
  501. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  502. /// <exception cref="OverflowException">(Asynchronous) The number of elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  503. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  504. public static IObservable<int> Count<TSource>(this IObservable<TSource> source)
  505. {
  506. if (source == null)
  507. throw new ArgumentNullException("source");
  508. return s_impl.Count<TSource>(source);
  509. }
  510. /// <summary>
  511. /// Returns an observable sequence containing an <see cref="T:System.Int32" /> that represents how many elements in the specified observable sequence satisfy a condition.
  512. /// </summary>
  513. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  514. /// <param name="source">An observable sequence that contains elements to be counted.</param>
  515. /// <param name="predicate">A function to test each element for a condition.</param>
  516. /// <returns>An observable sequence containing a single element with a number that represents how many elements in the input sequence satisfy the condition in the predicate function.</returns>
  517. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  518. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  519. public static IObservable<int> Count<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  520. {
  521. if (source == null)
  522. throw new ArgumentNullException("source");
  523. if (predicate == null)
  524. throw new ArgumentNullException("predicate");
  525. return s_impl.Count<TSource>(source, predicate);
  526. }
  527. #endregion
  528. #region + ElementAt +
  529. /// <summary>
  530. /// Returns the element at a specified index in a sequence.
  531. /// </summary>
  532. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  533. /// <param name="source">Observable sequence to return the element from.</param>
  534. /// <param name="index">The zero-based index of the element to retrieve.</param>
  535. /// <returns>An observable sequence that produces the element at the specified position in the source sequence.</returns>
  536. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  537. /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than zero.</exception>
  538. /// <exception cref="ArgumentOutOfRangeException">(Asynchronous) <paramref name="index"/> is greater than or equal to the number of elements in the source sequence.</exception>
  539. public static IObservable<TSource> ElementAt<TSource>(this IObservable<TSource> source, int index)
  540. {
  541. if (source == null)
  542. throw new ArgumentNullException("source");
  543. if (index < 0)
  544. throw new ArgumentOutOfRangeException("index");
  545. return s_impl.ElementAt<TSource>(source, index);
  546. }
  547. #endregion
  548. #region + ElementAtOrDefault +
  549. /// <summary>
  550. /// Returns the element at a specified index in a sequence or a default value if the index is out of range.
  551. /// </summary>
  552. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  553. /// <param name="source">Observable sequence to return the element from.</param>
  554. /// <param name="index">The zero-based index of the element to retrieve.</param>
  555. /// <returns>An observable sequence that produces the element at the specified position in the source sequence, or a default value if the index is outside the bounds of the source sequence.</returns>
  556. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  557. /// <exception cref="ArgumentOutOfRangeException"><paramref name="index"/> is less than zero.</exception>
  558. public static IObservable<TSource> ElementAtOrDefault<TSource>(this IObservable<TSource> source, int index)
  559. {
  560. if (source == null)
  561. throw new ArgumentNullException("source");
  562. if (index < 0)
  563. throw new ArgumentOutOfRangeException("index");
  564. return s_impl.ElementAtOrDefault<TSource>(source, index);
  565. }
  566. #endregion
  567. #region + FirstAsync +
  568. /// <summary>
  569. /// Returns the first element of an observable sequence.
  570. /// </summary>
  571. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  572. /// <param name="source">Source observable sequence.</param>
  573. /// <returns>Sequence containing the first element in the observable sequence.</returns>
  574. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  575. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  576. public static IObservable<TSource> FirstAsync<TSource>(this IObservable<TSource> source)
  577. {
  578. if (source == null)
  579. throw new ArgumentNullException("source");
  580. return s_impl.FirstAsync<TSource>(source);
  581. }
  582. /// <summary>
  583. /// Returns the first element of an observable sequence that satisfies the condition in the predicate.
  584. /// </summary>
  585. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  586. /// <param name="source">Source observable sequence.</param>
  587. /// <param name="predicate">A predicate function to evaluate for elements in the source sequence.</param>
  588. /// <returns>Sequence containing the first element in the observable sequence that satisfies the condition in the predicate.</returns>
  589. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  590. /// <exception cref="InvalidOperationException">(Asynchronous) No element satisfies the condition in the predicate. -or- The source sequence is empty.</exception>
  591. public static IObservable<TSource> FirstAsync<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  592. {
  593. if (source == null)
  594. throw new ArgumentNullException("source");
  595. if (predicate == null)
  596. throw new ArgumentNullException("predicate");
  597. return s_impl.FirstAsync<TSource>(source, predicate);
  598. }
  599. #endregion
  600. #region + FirstOrDefaultAsync +
  601. /// <summary>
  602. /// Returns the first element of an observable sequence, or a default value if no such element exists.
  603. /// </summary>
  604. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  605. /// <param name="source">Source observable sequence.</param>
  606. /// <returns>Sequence containing the first element in the observable sequence, or a default value if no such element exists.</returns>
  607. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  608. public static IObservable<TSource> FirstOrDefaultAsync<TSource>(this IObservable<TSource> source)
  609. {
  610. if (source == null)
  611. throw new ArgumentNullException("source");
  612. return s_impl.FirstOrDefaultAsync<TSource>(source);
  613. }
  614. /// <summary>
  615. /// Returns the first element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
  616. /// </summary>
  617. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  618. /// <param name="source">Source observable sequence.</param>
  619. /// <param name="predicate">A predicate function to evaluate for elements in the source sequence.</param>
  620. /// <returns>Sequence containing the first element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.</returns>
  621. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  622. public static IObservable<TSource> FirstOrDefaultAsync<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  623. {
  624. if (source == null)
  625. throw new ArgumentNullException("source");
  626. if (predicate == null)
  627. throw new ArgumentNullException("predicate");
  628. return s_impl.FirstOrDefaultAsync<TSource>(source, predicate);
  629. }
  630. #endregion
  631. #region + IsEmpty +
  632. /// <summary>
  633. /// Determines whether an observable sequence is empty.
  634. /// </summary>
  635. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  636. /// <param name="source">An observable sequence to check for emptiness.</param>
  637. /// <returns>An observable sequence containing a single element determining whether the source sequence is empty.</returns>
  638. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  639. public static IObservable<bool> IsEmpty<TSource>(this IObservable<TSource> source)
  640. {
  641. if (source == null)
  642. throw new ArgumentNullException("source");
  643. return s_impl.IsEmpty<TSource>(source);
  644. }
  645. #endregion
  646. #region + LastAsync +
  647. /// <summary>
  648. /// Returns the last element of an observable sequence.
  649. /// </summary>
  650. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  651. /// <param name="source">Source observable sequence.</param>
  652. /// <returns>Sequence containing the last element in the observable sequence.</returns>
  653. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  654. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence is empty.</exception>
  655. public static IObservable<TSource> LastAsync<TSource>(this IObservable<TSource> source)
  656. {
  657. if (source == null)
  658. throw new ArgumentNullException("source");
  659. return s_impl.LastAsync<TSource>(source);
  660. }
  661. /// <summary>
  662. /// Returns the last element of an observable sequence that satisfies the condition in the predicate.
  663. /// </summary>
  664. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  665. /// <param name="source">Source observable sequence.</param>
  666. /// <param name="predicate">A predicate function to evaluate for elements in the source sequence.</param>
  667. /// <returns>Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.</returns>
  668. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  669. /// <exception cref="InvalidOperationException">(Asynchronous) No element satisfies the condition in the predicate. -or- The source sequence is empty.</exception>
  670. public static IObservable<TSource> LastAsync<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  671. {
  672. if (source == null)
  673. throw new ArgumentNullException("source");
  674. if (predicate == null)
  675. throw new ArgumentNullException("predicate");
  676. return s_impl.LastAsync<TSource>(source, predicate);
  677. }
  678. #endregion
  679. #region + LastOrDefaultAsync +
  680. /// <summary>
  681. /// Returns the last element of an observable sequence, or a default value if no such element exists.
  682. /// </summary>
  683. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  684. /// <param name="source">Source observable sequence.</param>
  685. /// <returns>Sequence containing the last element in the observable sequence, or a default value if no such element exists.</returns>
  686. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  687. public static IObservable<TSource> LastOrDefaultAsync<TSource>(this IObservable<TSource> source)
  688. {
  689. if (source == null)
  690. throw new ArgumentNullException("source");
  691. return s_impl.LastOrDefaultAsync<TSource>(source);
  692. }
  693. /// <summary>
  694. /// Returns the last element of an observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.
  695. /// </summary>
  696. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  697. /// <param name="source">Source observable sequence.</param>
  698. /// <param name="predicate">A predicate function to evaluate for elements in the source sequence.</param>
  699. /// <returns>Sequence containing the last element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.</returns>
  700. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  701. public static IObservable<TSource> LastOrDefaultAsync<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  702. {
  703. if (source == null)
  704. throw new ArgumentNullException("source");
  705. if (predicate == null)
  706. throw new ArgumentNullException("predicate");
  707. return s_impl.LastOrDefaultAsync<TSource>(source, predicate);
  708. }
  709. #endregion
  710. #region + LongCount +
  711. /// <summary>
  712. /// Returns an observable sequence containing an <see cref="T:System.Int64" /> that represents the total number of elements in an observable sequence.
  713. /// </summary>
  714. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  715. /// <param name="source">An observable sequence that contains elements to be counted.</param>
  716. /// <returns>An observable sequence containing a single element with the number of elements in the input sequence.</returns>
  717. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  718. /// <exception cref="OverflowException">(Asynchronous) The number of elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  719. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  720. public static IObservable<long> LongCount<TSource>(this IObservable<TSource> source)
  721. {
  722. if (source == null)
  723. throw new ArgumentNullException("source");
  724. return s_impl.LongCount<TSource>(source);
  725. }
  726. /// <summary>
  727. /// Returns an observable sequence containing an <see cref="T:System.Int64" /> that represents how many elements in the specified observable sequence satisfy a condition.
  728. /// </summary>
  729. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  730. /// <param name="source">An observable sequence that contains elements to be counted.</param>
  731. /// <param name="predicate">A function to test each element for a condition.</param>
  732. /// <returns>An observable sequence containing a single element with a number that represents how many elements in the input sequence satisfy the condition in the predicate function.</returns>
  733. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  734. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  735. public static IObservable<long> LongCount<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  736. {
  737. if (source == null)
  738. throw new ArgumentNullException("source");
  739. if (predicate == null)
  740. throw new ArgumentNullException("predicate");
  741. return s_impl.LongCount<TSource>(source, predicate);
  742. }
  743. #endregion
  744. #region + Max +
  745. /// <summary>
  746. /// Returns the maximum element in an observable sequence.
  747. /// </summary>
  748. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  749. /// <param name="source">An observable sequence to determine the maximum element of.</param>
  750. /// <returns>An observable sequence containing a single element with the maximum element in the source sequence.</returns>
  751. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  752. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  753. public static IObservable<TSource> Max<TSource>(this IObservable<TSource> source)
  754. {
  755. if (source == null)
  756. throw new ArgumentNullException("source");
  757. return s_impl.Max<TSource>(source);
  758. }
  759. /// <summary>
  760. /// Returns the maximum value in an observable sequence according to the specified comparer.
  761. /// </summary>
  762. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  763. /// <param name="source">An observable sequence to determine the maximum element of.</param>
  764. /// <param name="comparer">Comparer used to compare elements.</param>
  765. /// <returns>An observable sequence containing a single element with the maximum element in the source sequence.</returns>
  766. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="comparer"/> is null.</exception>
  767. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  768. public static IObservable<TSource> Max<TSource>(this IObservable<TSource> source, IComparer<TSource> comparer)
  769. {
  770. if (source == null)
  771. throw new ArgumentNullException("source");
  772. if (comparer == null)
  773. throw new ArgumentNullException("comparer");
  774. return s_impl.Max<TSource>(source, comparer);
  775. }
  776. /// <summary>
  777. /// Returns the maximum value in an observable sequence of <see cref="T:System.Double" /> values.
  778. /// </summary>
  779. /// <param name="source">A sequence of <see cref="T:System.Double" /> values to determine the maximum value of.</param>
  780. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  781. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  782. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  783. public static IObservable<double> Max(this IObservable<double> source)
  784. {
  785. if (source == null)
  786. throw new ArgumentNullException("source");
  787. return s_impl.Max(source);
  788. }
  789. /// <summary>
  790. /// Returns the maximum value in an observable sequence of <see cref="T:System.Single" /> values.
  791. /// </summary>
  792. /// <param name="source">A sequence of <see cref="T:System.Single" /> values to determine the maximum value of.</param>
  793. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  794. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  795. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  796. public static IObservable<float> Max(this IObservable<float> source)
  797. {
  798. if (source == null)
  799. throw new ArgumentNullException("source");
  800. return s_impl.Max(source);
  801. }
  802. /// <summary>
  803. /// Returns the maximum value in an observable sequence of <see cref="T:System.Decimal" /> values.
  804. /// </summary>
  805. /// <param name="source">A sequence of <see cref="T:System.Decimal" /> values to determine the maximum value of.</param>
  806. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  807. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  808. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  809. public static IObservable<decimal> Max(this IObservable<decimal> source)
  810. {
  811. if (source == null)
  812. throw new ArgumentNullException("source");
  813. return s_impl.Max(source);
  814. }
  815. /// <summary>
  816. /// Returns the maximum value in an observable sequence of <see cref="T:System.Int32" /> values.
  817. /// </summary>
  818. /// <param name="source">A sequence of <see cref="T:System.Int32" /> values to determine the maximum value of.</param>
  819. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  820. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  821. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  822. public static IObservable<int> Max(this IObservable<int> source)
  823. {
  824. if (source == null)
  825. throw new ArgumentNullException("source");
  826. return s_impl.Max(source);
  827. }
  828. /// <summary>
  829. /// Returns the maximum value in an observable sequence of <see cref="T:System.Int64" /> values.
  830. /// </summary>
  831. /// <param name="source">A sequence of <see cref="T:System.Int64" /> values to determine the maximum value of.</param>
  832. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  833. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  834. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  835. public static IObservable<long> Max(this IObservable<long> source)
  836. {
  837. if (source == null)
  838. throw new ArgumentNullException("source");
  839. return s_impl.Max(source);
  840. }
  841. /// <summary>
  842. /// Returns the maximum value in an observable sequence of nullable <see cref="T:System.Double" /> values.
  843. /// </summary>
  844. /// <param name="source">A sequence of nullable <see cref="T:System.Double" /> values to determine the maximum value of.</param>
  845. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  846. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  847. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  848. public static IObservable<double?> Max(this IObservable<double?> source)
  849. {
  850. if (source == null)
  851. throw new ArgumentNullException("source");
  852. return s_impl.Max(source);
  853. }
  854. /// <summary>
  855. /// Returns the maximum value in an observable sequence of nullable <see cref="T:System.Single" /> values.
  856. /// </summary>
  857. /// <param name="source">A sequence of nullable <see cref="T:System.Single" /> values to determine the maximum value of.</param>
  858. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  859. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  860. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  861. public static IObservable<float?> Max(this IObservable<float?> source)
  862. {
  863. if (source == null)
  864. throw new ArgumentNullException("source");
  865. return s_impl.Max(source);
  866. }
  867. /// <summary>
  868. /// Returns the maximum value in an observable sequence of nullable <see cref="T:System.Decimal" /> values.
  869. /// </summary>
  870. /// <param name="source">A sequence of nullable <see cref="T:System.Decimal" /> values to determine the maximum value of.</param>
  871. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  872. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  873. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  874. public static IObservable<decimal?> Max(this IObservable<decimal?> source)
  875. {
  876. if (source == null)
  877. throw new ArgumentNullException("source");
  878. return s_impl.Max(source);
  879. }
  880. /// <summary>
  881. /// Returns the maximum value in an observable sequence of nullable <see cref="T:System.Int32" /> values.
  882. /// </summary>
  883. /// <param name="source">A sequence of nullable <see cref="T:System.Int32" /> values to determine the maximum value of.</param>
  884. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  885. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  886. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  887. public static IObservable<int?> Max(this IObservable<int?> source)
  888. {
  889. if (source == null)
  890. throw new ArgumentNullException("source");
  891. return s_impl.Max(source);
  892. }
  893. /// <summary>
  894. /// Returns the maximum value in an observable sequence of nullable <see cref="T:System.Int64" /> values.
  895. /// </summary>
  896. /// <param name="source">A sequence of nullable <see cref="T:System.Int64" /> values to determine the maximum value of.</param>
  897. /// <returns>An observable sequence containing a single element with the maximum value in the source sequence.</returns>
  898. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  899. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  900. public static IObservable<long?> Max(this IObservable<long?> source)
  901. {
  902. if (source == null)
  903. throw new ArgumentNullException("source");
  904. return s_impl.Max(source);
  905. }
  906. /// <summary>
  907. /// Invokes a transform function on each element of a sequence and returns the maximum value.
  908. /// </summary>
  909. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  910. /// <typeparam name="TResult">The type of the objects derived from the elements in the source sequence to determine the maximum of.</typeparam>
  911. /// <param name="source">An observable sequence to determine the mimimum element of.</param>
  912. /// <param name="selector">A transform function to apply to each element.</param>
  913. /// <returns>An observable sequence containing a single element with the value that corresponds to the maximum element in the source sequence.</returns>
  914. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  915. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  916. public static IObservable<TResult> Max<TSource, TResult>(this IObservable<TSource> source, Func<TSource, TResult> selector)
  917. {
  918. if (source == null)
  919. throw new ArgumentNullException("source");
  920. if (selector == null)
  921. throw new ArgumentNullException("selector");
  922. return s_impl.Max<TSource, TResult>(source, selector);
  923. }
  924. /// <summary>
  925. /// Invokes a transform function on each element of a sequence and returns the maximum value according to the specified comparer.
  926. /// </summary>
  927. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  928. /// <typeparam name="TResult">The type of the objects derived from the elements in the source sequence to determine the maximum of.</typeparam>
  929. /// <param name="source">An observable sequence to determine the mimimum element of.</param>
  930. /// <param name="selector">A transform function to apply to each element.</param>
  931. /// <param name="comparer">Comparer used to compare elements.</param>
  932. /// <returns>An observable sequence containing a single element with the value that corresponds to the maximum element in the source sequence.</returns>
  933. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> or <paramref name="comparer"/> is null.</exception>
  934. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  935. public static IObservable<TResult> Max<TSource, TResult>(this IObservable<TSource> source, Func<TSource, TResult> selector, IComparer<TResult> comparer)
  936. {
  937. if (source == null)
  938. throw new ArgumentNullException("source");
  939. if (selector == null)
  940. throw new ArgumentNullException("selector");
  941. if (comparer == null)
  942. throw new ArgumentNullException("comparer");
  943. return s_impl.Max<TSource, TResult>(source, selector, comparer);
  944. }
  945. /// <summary>
  946. /// Invokes a transform function on each element of a sequence and returns the maximum <see cref="T:System.Double" /> value.
  947. /// </summary>
  948. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  949. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  950. /// <param name="selector">A transform function to apply to each element.</param>
  951. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Double" /> that corresponds to the maximum value in the source sequence.</returns>
  952. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  953. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  954. public static IObservable<double> Max<TSource>(this IObservable<TSource> source, Func<TSource, double> selector)
  955. {
  956. if (source == null)
  957. throw new ArgumentNullException("source");
  958. if (selector == null)
  959. throw new ArgumentNullException("selector");
  960. return s_impl.Max<TSource>(source, selector);
  961. }
  962. /// <summary>
  963. /// Invokes a transform function on each element of a sequence and returns the maximum <see cref="T:System.Single" /> value.
  964. /// </summary>
  965. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  966. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  967. /// <param name="selector">A transform function to apply to each element.</param>
  968. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Single" /> that corresponds to the maximum value in the source sequence.</returns>
  969. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  970. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  971. public static IObservable<float> Max<TSource>(this IObservable<TSource> source, Func<TSource, float> selector)
  972. {
  973. if (source == null)
  974. throw new ArgumentNullException("source");
  975. if (selector == null)
  976. throw new ArgumentNullException("selector");
  977. return s_impl.Max<TSource>(source, selector);
  978. }
  979. /// <summary>
  980. /// Invokes a transform function on each element of a sequence and returns the maximum <see cref="T:System.Decimal" /> value.
  981. /// </summary>
  982. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  983. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  984. /// <param name="selector">A transform function to apply to each element.</param>
  985. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Decimal" /> that corresponds to the maximum value in the source sequence.</returns>
  986. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  987. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  988. public static IObservable<decimal> Max<TSource>(this IObservable<TSource> source, Func<TSource, decimal> selector)
  989. {
  990. if (source == null)
  991. throw new ArgumentNullException("source");
  992. if (selector == null)
  993. throw new ArgumentNullException("selector");
  994. return s_impl.Max<TSource>(source, selector);
  995. }
  996. /// <summary>
  997. /// Invokes a transform function on each element of a sequence and returns the maximum <see cref="T:System.Int32" /> value.
  998. /// </summary>
  999. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1000. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  1001. /// <param name="selector">A transform function to apply to each element.</param>
  1002. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Int32" /> that corresponds to the maximum value in the source sequence.</returns>
  1003. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1004. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1005. public static IObservable<int> Max<TSource>(this IObservable<TSource> source, Func<TSource, int> selector)
  1006. {
  1007. if (source == null)
  1008. throw new ArgumentNullException("source");
  1009. if (selector == null)
  1010. throw new ArgumentNullException("selector");
  1011. return s_impl.Max<TSource>(source, selector);
  1012. }
  1013. /// <summary>
  1014. /// Invokes a transform function on each element of a sequence and returns the maximum <see cref="T:System.Int64" /> value.
  1015. /// </summary>
  1016. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1017. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  1018. /// <param name="selector">A transform function to apply to each element.</param>
  1019. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Int64" /> that corresponds to the maximum value in the source sequence.</returns>
  1020. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1021. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1022. public static IObservable<long> Max<TSource>(this IObservable<TSource> source, Func<TSource, long> selector)
  1023. {
  1024. if (source == null)
  1025. throw new ArgumentNullException("source");
  1026. if (selector == null)
  1027. throw new ArgumentNullException("selector");
  1028. return s_impl.Max<TSource>(source, selector);
  1029. }
  1030. /// <summary>
  1031. /// Invokes a transform function on each element of a sequence and returns the maximum nullable <see cref="T:System.Double" /> value.
  1032. /// </summary>
  1033. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1034. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  1035. /// <param name="selector">A transform function to apply to each element.</param>
  1036. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Double&gt;" /> that corresponds to the maximum value in the source sequence.</returns>
  1037. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1038. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1039. public static IObservable<double?> Max<TSource>(this IObservable<TSource> source, Func<TSource, double?> selector)
  1040. {
  1041. if (source == null)
  1042. throw new ArgumentNullException("source");
  1043. if (selector == null)
  1044. throw new ArgumentNullException("selector");
  1045. return s_impl.Max<TSource>(source, selector);
  1046. }
  1047. /// <summary>
  1048. /// Invokes a transform function on each element of a sequence and returns the maximum nullable <see cref="T:System.Single" /> value.
  1049. /// </summary>
  1050. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1051. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  1052. /// <param name="selector">A transform function to apply to each element.</param>
  1053. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Single&gt;" /> that corresponds to the maximum value in the source sequence.</returns>
  1054. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1055. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1056. public static IObservable<float?> Max<TSource>(this IObservable<TSource> source, Func<TSource, float?> selector)
  1057. {
  1058. if (source == null)
  1059. throw new ArgumentNullException("source");
  1060. if (selector == null)
  1061. throw new ArgumentNullException("selector");
  1062. return s_impl.Max<TSource>(source, selector);
  1063. }
  1064. /// <summary>
  1065. /// Invokes a transform function on each element of a sequence and returns the maximum nullable <see cref="T:System.Decimal" /> value.
  1066. /// </summary>
  1067. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1068. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  1069. /// <param name="selector">A transform function to apply to each element.</param>
  1070. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Decimal&gt;" /> that corresponds to the maximum value in the source sequence.</returns>
  1071. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1072. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1073. public static IObservable<decimal?> Max<TSource>(this IObservable<TSource> source, Func<TSource, decimal?> selector)
  1074. {
  1075. if (source == null)
  1076. throw new ArgumentNullException("source");
  1077. if (selector == null)
  1078. throw new ArgumentNullException("selector");
  1079. return s_impl.Max<TSource>(source, selector);
  1080. }
  1081. /// <summary>
  1082. /// Invokes a transform function on each element of a sequence and returns the maximum nullable <see cref="T:System.Int32" /> value.
  1083. /// </summary>
  1084. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1085. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  1086. /// <param name="selector">A transform function to apply to each element.</param>
  1087. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Int32&gt;" /> that corresponds to the maximum value in the source sequence.</returns>
  1088. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1089. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1090. public static IObservable<int?> Max<TSource>(this IObservable<TSource> source, Func<TSource, int?> selector)
  1091. {
  1092. if (source == null)
  1093. throw new ArgumentNullException("source");
  1094. if (selector == null)
  1095. throw new ArgumentNullException("selector");
  1096. return s_impl.Max<TSource>(source, selector);
  1097. }
  1098. /// <summary>
  1099. /// Invokes a transform function on each element of a sequence and returns the maximum nullable <see cref="T:System.Int64" /> value.
  1100. /// </summary>
  1101. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1102. /// <param name="source">A sequence of values to determine the maximum value of.</param>
  1103. /// <param name="selector">A transform function to apply to each element.</param>
  1104. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Int64&gt;" /> that corresponds to the maximum value in the source sequence.</returns>
  1105. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1106. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1107. public static IObservable<long?> Max<TSource>(this IObservable<TSource> source, Func<TSource, long?> selector)
  1108. {
  1109. if (source == null)
  1110. throw new ArgumentNullException("source");
  1111. if (selector == null)
  1112. throw new ArgumentNullException("selector");
  1113. return s_impl.Max<TSource>(source, selector);
  1114. }
  1115. #endregion
  1116. #region + MaxBy +
  1117. /// <summary>
  1118. /// Returns the elements in an observable sequence with the maximum key value.
  1119. /// </summary>
  1120. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1121. /// <typeparam name="TKey">The type of the key computed for each element in the source sequence.</typeparam>
  1122. /// <param name="source">An observable sequence to get the maximum elements for.</param>
  1123. /// <param name="keySelector">Key selector function.</param>
  1124. /// <returns>An observable sequence containing a list of zero or more elements that have a maximum key value.</returns>
  1125. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> is null.</exception>
  1126. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1127. public static IObservable<IList<TSource>> MaxBy<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector)
  1128. {
  1129. if (source == null)
  1130. throw new ArgumentNullException("source");
  1131. if (keySelector == null)
  1132. throw new ArgumentNullException("keySelector");
  1133. return s_impl.MaxBy<TSource, TKey>(source, keySelector);
  1134. }
  1135. /// <summary>
  1136. /// Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
  1137. /// </summary>
  1138. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1139. /// <typeparam name="TKey">The type of the key computed for each element in the source sequence.</typeparam>
  1140. /// <param name="source">An observable sequence to get the maximum elements for.</param>
  1141. /// <param name="keySelector">Key selector function.</param>
  1142. /// <param name="comparer">Comparer used to compare key values.</param>
  1143. /// <returns>An observable sequence containing a list of zero or more elements that have a maximum key value.</returns>
  1144. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="comparer"/> is null.</exception>
  1145. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1146. public static IObservable<IList<TSource>> MaxBy<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
  1147. {
  1148. if (source == null)
  1149. throw new ArgumentNullException("source");
  1150. if (keySelector == null)
  1151. throw new ArgumentNullException("keySelector");
  1152. if (comparer == null)
  1153. throw new ArgumentNullException("comparer");
  1154. return s_impl.MaxBy<TSource, TKey>(source, keySelector, comparer);
  1155. }
  1156. #endregion
  1157. #region + Min +
  1158. /// <summary>
  1159. /// Returns the minimum element in an observable sequence.
  1160. /// </summary>
  1161. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1162. /// <param name="source">An observable sequence to determine the mimimum element of.</param>
  1163. /// <returns>An observable sequence containing a single element with the minimum element in the source sequence.</returns>
  1164. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1165. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1166. public static IObservable<TSource> Min<TSource>(this IObservable<TSource> source)
  1167. {
  1168. if (source == null)
  1169. throw new ArgumentNullException("source");
  1170. return s_impl.Min<TSource>(source);
  1171. }
  1172. /// <summary>
  1173. /// Returns the minimum element in an observable sequence according to the specified comparer.
  1174. /// </summary>
  1175. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1176. /// <param name="source">An observable sequence to determine the mimimum element of.</param>
  1177. /// <param name="comparer">Comparer used to compare elements.</param>
  1178. /// <returns>An observable sequence containing a single element with the minimum element in the source sequence.</returns>
  1179. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="comparer"/> is null.</exception>
  1180. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1181. public static IObservable<TSource> Min<TSource>(this IObservable<TSource> source, IComparer<TSource> comparer)
  1182. {
  1183. if (source == null)
  1184. throw new ArgumentNullException("source");
  1185. if (comparer == null)
  1186. throw new ArgumentNullException("comparer");
  1187. return s_impl.Min<TSource>(source, comparer);
  1188. }
  1189. /// <summary>
  1190. /// Returns the minimum value in an observable sequence of <see cref="T:System.Double" /> values.
  1191. /// </summary>
  1192. /// <param name="source">A sequence of <see cref="T:System.Double" /> values to determine the minimum value of.</param>
  1193. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1194. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1195. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1196. public static IObservable<double> Min(this IObservable<double> source)
  1197. {
  1198. if (source == null)
  1199. throw new ArgumentNullException("source");
  1200. return s_impl.Min(source);
  1201. }
  1202. /// <summary>
  1203. /// Returns the minimum value in an observable sequence of <see cref="T:System.Single" /> values.
  1204. /// </summary>
  1205. /// <param name="source">A sequence of <see cref="T:System.Single" /> values to determine the minimum value of.</param>
  1206. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1207. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1208. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1209. public static IObservable<float> Min(this IObservable<float> source)
  1210. {
  1211. if (source == null)
  1212. throw new ArgumentNullException("source");
  1213. return s_impl.Min(source);
  1214. }
  1215. /// <summary>
  1216. /// Returns the minimum value in an observable sequence of <see cref="T:System.Decimal" /> values.
  1217. /// </summary>
  1218. /// <param name="source">A sequence of <see cref="T:System.Decimal" /> values to determine the minimum value of.</param>
  1219. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1220. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1221. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1222. public static IObservable<decimal> Min(this IObservable<decimal> source)
  1223. {
  1224. if (source == null)
  1225. throw new ArgumentNullException("source");
  1226. return s_impl.Min(source);
  1227. }
  1228. /// <summary>
  1229. /// Returns the minimum value in an observable sequence of <see cref="T:System.Int32" /> values.
  1230. /// </summary>
  1231. /// <param name="source">A sequence of <see cref="T:System.Int32" /> values to determine the minimum value of.</param>
  1232. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1233. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1234. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1235. public static IObservable<int> Min(this IObservable<int> source)
  1236. {
  1237. if (source == null)
  1238. throw new ArgumentNullException("source");
  1239. return s_impl.Min(source);
  1240. }
  1241. /// <summary>
  1242. /// Returns the minimum value in an observable sequence of <see cref="T:System.Int64" /> values.
  1243. /// </summary>
  1244. /// <param name="source">A sequence of <see cref="T:System.Int64" /> values to determine the minimum value of.</param>
  1245. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1246. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1247. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1248. public static IObservable<long> Min(this IObservable<long> source)
  1249. {
  1250. if (source == null)
  1251. throw new ArgumentNullException("source");
  1252. return s_impl.Min(source);
  1253. }
  1254. /// <summary>
  1255. /// Returns the minimum value in an observable sequence of nullable <see cref="T:System.Double" /> values.
  1256. /// </summary>
  1257. /// <param name="source">A sequence of nullable <see cref="T:System.Double" /> values to determine the minimum value of.</param>
  1258. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1259. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1260. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1261. public static IObservable<double?> Min(this IObservable<double?> source)
  1262. {
  1263. if (source == null)
  1264. throw new ArgumentNullException("source");
  1265. return s_impl.Min(source);
  1266. }
  1267. /// <summary>
  1268. /// Returns the minimum value in an observable sequence of nullable <see cref="T:System.Single" /> values.
  1269. /// </summary>
  1270. /// <param name="source">A sequence of nullable <see cref="T:System.Single" /> values to determine the minimum value of.</param>
  1271. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1272. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1273. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1274. public static IObservable<float?> Min(this IObservable<float?> source)
  1275. {
  1276. if (source == null)
  1277. throw new ArgumentNullException("source");
  1278. return s_impl.Min(source);
  1279. }
  1280. /// <summary>
  1281. /// Returns the minimum value in an observable sequence of nullable <see cref="T:System.Decimal" /> values.
  1282. /// </summary>
  1283. /// <param name="source">A sequence of nullable <see cref="T:System.Decimal" /> values to determine the minimum value of.</param>
  1284. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1285. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1286. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1287. public static IObservable<decimal?> Min(this IObservable<decimal?> source)
  1288. {
  1289. if (source == null)
  1290. throw new ArgumentNullException("source");
  1291. return s_impl.Min(source);
  1292. }
  1293. /// <summary>
  1294. /// Returns the minimum value in an observable sequence of nullable <see cref="T:System.Int32" /> values.
  1295. /// </summary>
  1296. /// <param name="source">A sequence of nullable <see cref="T:System.Int32" /> values to determine the minimum value of.</param>
  1297. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1298. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1299. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1300. public static IObservable<int?> Min(this IObservable<int?> source)
  1301. {
  1302. if (source == null)
  1303. throw new ArgumentNullException("source");
  1304. return s_impl.Min(source);
  1305. }
  1306. /// <summary>
  1307. /// Returns the minimum value in an observable sequence of nullable <see cref="T:System.Int64" /> values.
  1308. /// </summary>
  1309. /// <param name="source">A sequence of nullable <see cref="T:System.Int64" /> values to determine the minimum value of.</param>
  1310. /// <returns>An observable sequence containing a single element with the minimum value in the source sequence.</returns>
  1311. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1312. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1313. public static IObservable<long?> Min(this IObservable<long?> source)
  1314. {
  1315. if (source == null)
  1316. throw new ArgumentNullException("source");
  1317. return s_impl.Min(source);
  1318. }
  1319. /// <summary>
  1320. /// Invokes a transform function on each element of a sequence and returns the minimum value.
  1321. /// </summary>
  1322. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1323. /// <typeparam name="TResult">The type of the objects derived from the elements in the source sequence to determine the minimum of.</typeparam>
  1324. /// <param name="source">An observable sequence to determine the mimimum element of.</param>
  1325. /// <param name="selector">A transform function to apply to each element.</param>
  1326. /// <returns>An observable sequence containing a single element with the value that corresponds to the minimum element in the source sequence.</returns>
  1327. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1328. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1329. public static IObservable<TResult> Min<TSource, TResult>(this IObservable<TSource> source, Func<TSource, TResult> selector)
  1330. {
  1331. if (source == null)
  1332. throw new ArgumentNullException("source");
  1333. if (selector == null)
  1334. throw new ArgumentNullException("selector");
  1335. return s_impl.Min<TSource, TResult>(source, selector);
  1336. }
  1337. /// <summary>
  1338. /// Invokes a transform function on each element of a sequence and returns the minimum value according to the specified comparer.
  1339. /// </summary>
  1340. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1341. /// <typeparam name="TResult">The type of the objects derived from the elements in the source sequence to determine the minimum of.</typeparam>
  1342. /// <param name="source">An observable sequence to determine the mimimum element of.</param>
  1343. /// <param name="selector">A transform function to apply to each element.</param>
  1344. /// <param name="comparer">Comparer used to compare elements.</param>
  1345. /// <returns>An observable sequence containing a single element with the value that corresponds to the minimum element in the source sequence.</returns>
  1346. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> or <paramref name="comparer"/> is null.</exception>
  1347. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1348. public static IObservable<TResult> Min<TSource, TResult>(this IObservable<TSource> source, Func<TSource, TResult> selector, IComparer<TResult> comparer)
  1349. {
  1350. if (source == null)
  1351. throw new ArgumentNullException("source");
  1352. if (selector == null)
  1353. throw new ArgumentNullException("selector");
  1354. if (comparer == null)
  1355. throw new ArgumentNullException("comparer");
  1356. return s_impl.Min<TSource, TResult>(source, selector, comparer);
  1357. }
  1358. /// <summary>
  1359. /// Invokes a transform function on each element of a sequence and returns the minimum <see cref="T:System.Double" /> value.
  1360. /// </summary>
  1361. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1362. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1363. /// <param name="selector">A transform function to apply to each element.</param>
  1364. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Double" /> that corresponds to the minimum value in the source sequence.</returns>
  1365. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1366. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1367. public static IObservable<double> Min<TSource>(this IObservable<TSource> source, Func<TSource, double> selector)
  1368. {
  1369. if (source == null)
  1370. throw new ArgumentNullException("source");
  1371. if (selector == null)
  1372. throw new ArgumentNullException("selector");
  1373. return s_impl.Min<TSource>(source, selector);
  1374. }
  1375. /// <summary>
  1376. /// Invokes a transform function on each element of a sequence and returns the minimum <see cref="T:System.Single" /> value.
  1377. /// </summary>
  1378. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1379. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1380. /// <param name="selector">A transform function to apply to each element.</param>
  1381. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Single" /> that corresponds to the minimum value in the source sequence.</returns>
  1382. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1383. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1384. public static IObservable<float> Min<TSource>(this IObservable<TSource> source, Func<TSource, float> selector)
  1385. {
  1386. if (source == null)
  1387. throw new ArgumentNullException("source");
  1388. if (selector == null)
  1389. throw new ArgumentNullException("selector");
  1390. return s_impl.Min<TSource>(source, selector);
  1391. }
  1392. /// <summary>
  1393. /// Invokes a transform function on each element of a sequence and returns the minimum <see cref="T:System.Decimal" /> value.
  1394. /// </summary>
  1395. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1396. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1397. /// <param name="selector">A transform function to apply to each element.</param>
  1398. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Decimal" /> that corresponds to the minimum value in the source sequence.</returns>
  1399. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1400. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1401. public static IObservable<decimal> Min<TSource>(this IObservable<TSource> source, Func<TSource, decimal> selector)
  1402. {
  1403. if (source == null)
  1404. throw new ArgumentNullException("source");
  1405. if (selector == null)
  1406. throw new ArgumentNullException("selector");
  1407. return s_impl.Min<TSource>(source, selector);
  1408. }
  1409. /// <summary>
  1410. /// Invokes a transform function on each element of a sequence and returns the minimum <see cref="T:System.Int32" /> value.
  1411. /// </summary>
  1412. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1413. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1414. /// <param name="selector">A transform function to apply to each element.</param>
  1415. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Int32" /> that corresponds to the minimum value in the source sequence.</returns>
  1416. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1417. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1418. public static IObservable<int> Min<TSource>(this IObservable<TSource> source, Func<TSource, int> selector)
  1419. {
  1420. if (source == null)
  1421. throw new ArgumentNullException("source");
  1422. if (selector == null)
  1423. throw new ArgumentNullException("selector");
  1424. return s_impl.Min<TSource>(source, selector);
  1425. }
  1426. /// <summary>
  1427. /// Invokes a transform function on each element of a sequence and returns the minimum <see cref="T:System.Int64" /> value.
  1428. /// </summary>
  1429. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1430. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1431. /// <param name="selector">A transform function to apply to each element.</param>
  1432. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Int64" /> that corresponds to the minimum value in the source sequence.</returns>
  1433. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1434. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1435. public static IObservable<long> Min<TSource>(this IObservable<TSource> source, Func<TSource, long> selector)
  1436. {
  1437. if (source == null)
  1438. throw new ArgumentNullException("source");
  1439. if (selector == null)
  1440. throw new ArgumentNullException("selector");
  1441. return s_impl.Min<TSource>(source, selector);
  1442. }
  1443. /// <summary>
  1444. /// Invokes a transform function on each element of a sequence and returns the minimum nullable <see cref="T:System.Double" /> value.
  1445. /// </summary>
  1446. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1447. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1448. /// <param name="selector">A transform function to apply to each element.</param>
  1449. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Double&gt;" /> that corresponds to the minimum value in the source sequence.</returns>
  1450. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1451. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1452. public static IObservable<double?> Min<TSource>(this IObservable<TSource> source, Func<TSource, double?> selector)
  1453. {
  1454. if (source == null)
  1455. throw new ArgumentNullException("source");
  1456. if (selector == null)
  1457. throw new ArgumentNullException("selector");
  1458. return s_impl.Min<TSource>(source, selector);
  1459. }
  1460. /// <summary>
  1461. /// Invokes a transform function on each element of a sequence and returns the minimum nullable <see cref="T:System.Single" /> value.
  1462. /// </summary>
  1463. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1464. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1465. /// <param name="selector">A transform function to apply to each element.</param>
  1466. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Single&gt;" /> that corresponds to the minimum value in the source sequence.</returns>
  1467. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1468. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1469. public static IObservable<float?> Min<TSource>(this IObservable<TSource> source, Func<TSource, float?> selector)
  1470. {
  1471. if (source == null)
  1472. throw new ArgumentNullException("source");
  1473. if (selector == null)
  1474. throw new ArgumentNullException("selector");
  1475. return s_impl.Min<TSource>(source, selector);
  1476. }
  1477. /// <summary>
  1478. /// Invokes a transform function on each element of a sequence and returns the minimum nullable <see cref="T:System.Decimal" /> value.
  1479. /// </summary>
  1480. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1481. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1482. /// <param name="selector">A transform function to apply to each element.</param>
  1483. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Decimal&gt;" /> that corresponds to the minimum value in the source sequence.</returns>
  1484. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1485. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1486. public static IObservable<decimal?> Min<TSource>(this IObservable<TSource> source, Func<TSource, decimal?> selector)
  1487. {
  1488. if (source == null)
  1489. throw new ArgumentNullException("source");
  1490. if (selector == null)
  1491. throw new ArgumentNullException("selector");
  1492. return s_impl.Min<TSource>(source, selector);
  1493. }
  1494. /// <summary>
  1495. /// Invokes a transform function on each element of a sequence and returns the minimum nullable <see cref="T:System.Int32" /> value.
  1496. /// </summary>
  1497. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1498. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1499. /// <param name="selector">A transform function to apply to each element.</param>
  1500. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Int32&gt;" /> that corresponds to the minimum value in the source sequence.</returns>
  1501. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1502. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1503. public static IObservable<int?> Min<TSource>(this IObservable<TSource> source, Func<TSource, int?> selector)
  1504. {
  1505. if (source == null)
  1506. throw new ArgumentNullException("source");
  1507. if (selector == null)
  1508. throw new ArgumentNullException("selector");
  1509. return s_impl.Min<TSource>(source, selector);
  1510. }
  1511. /// <summary>
  1512. /// Invokes a transform function on each element of a sequence and returns the minimum nullable <see cref="T:System.Int64" /> value.
  1513. /// </summary>
  1514. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1515. /// <param name="source">A sequence of values to determine the minimum value of.</param>
  1516. /// <param name="selector">A transform function to apply to each element.</param>
  1517. /// <returns>An observable sequence containing a single element with the value of type <see cref="T:System.Nullable&lt;System.Int64&gt;" /> that corresponds to the minimum value in the source sequence.</returns>
  1518. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1519. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1520. public static IObservable<long?> Min<TSource>(this IObservable<TSource> source, Func<TSource, long?> selector)
  1521. {
  1522. if (source == null)
  1523. throw new ArgumentNullException("source");
  1524. if (selector == null)
  1525. throw new ArgumentNullException("selector");
  1526. return s_impl.Min<TSource>(source, selector);
  1527. }
  1528. #endregion
  1529. #region + MinBy +
  1530. /// <summary>
  1531. /// Returns the elements in an observable sequence with the minimum key value.
  1532. /// </summary>
  1533. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1534. /// <typeparam name="TKey">The type of the key computed for each element in the source sequence.</typeparam>
  1535. /// <param name="source">An observable sequence to get the minimum elements for.</param>
  1536. /// <param name="keySelector">Key selector function.</param>
  1537. /// <returns>An observable sequence containing a list of zero or more elements that have a minimum key value.</returns>
  1538. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> is null.</exception>
  1539. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1540. public static IObservable<IList<TSource>> MinBy<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector)
  1541. {
  1542. if (source == null)
  1543. throw new ArgumentNullException("source");
  1544. if (keySelector == null)
  1545. throw new ArgumentNullException("keySelector");
  1546. return s_impl.MinBy<TSource, TKey>(source, keySelector);
  1547. }
  1548. /// <summary>
  1549. /// Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
  1550. /// </summary>
  1551. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1552. /// <typeparam name="TKey">The type of the key computed for each element in the source sequence.</typeparam>
  1553. /// <param name="source">An observable sequence to get the minimum elements for.</param>
  1554. /// <param name="keySelector">Key selector function.</param>
  1555. /// <param name="comparer">Comparer used to compare key values.</param>
  1556. /// <returns>An observable sequence containing a list of zero or more elements that have a minimum key value.</returns>
  1557. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="comparer"/> is null.</exception>
  1558. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1559. public static IObservable<IList<TSource>> MinBy<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, IComparer<TKey> comparer)
  1560. {
  1561. if (source == null)
  1562. throw new ArgumentNullException("source");
  1563. if (keySelector == null)
  1564. throw new ArgumentNullException("keySelector");
  1565. if (comparer == null)
  1566. throw new ArgumentNullException("comparer");
  1567. return s_impl.MinBy<TSource, TKey>(source, keySelector, comparer);
  1568. }
  1569. #endregion
  1570. #region + SequenceEqual +
  1571. /// <summary>
  1572. /// Determines whether two sequences are equal by comparing the elements pairwise.
  1573. /// </summary>
  1574. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1575. /// <param name="first">First observable sequence to compare.</param>
  1576. /// <param name="second">Second observable sequence to compare.</param>
  1577. /// <returns>An observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the default equality comparer for their type.</returns>
  1578. /// <exception cref="ArgumentNullException"><paramref name="first"/> or <paramref name="second"/> is null.</exception>
  1579. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1580. public static IObservable<bool> SequenceEqual<TSource>(this IObservable<TSource> first, IObservable<TSource> second)
  1581. {
  1582. if (first == null)
  1583. throw new ArgumentNullException("first");
  1584. if (second == null)
  1585. throw new ArgumentNullException("second");
  1586. return s_impl.SequenceEqual<TSource>(first, second);
  1587. }
  1588. /// <summary>
  1589. /// Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.
  1590. /// </summary>
  1591. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1592. /// <param name="first">First observable sequence to compare.</param>
  1593. /// <param name="second">Second observable sequence to compare.</param>
  1594. /// <param name="comparer">Comparer used to compare elements of both sequences.</param>
  1595. /// <returns>An observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the specified equality comparer.</returns>
  1596. /// <exception cref="ArgumentNullException"><paramref name="first"/> or <paramref name="second"/> or <paramref name="comparer"/> is null.</exception>
  1597. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1598. public static IObservable<bool> SequenceEqual<TSource>(this IObservable<TSource> first, IObservable<TSource> second, IEqualityComparer<TSource> comparer)
  1599. {
  1600. if (first == null)
  1601. throw new ArgumentNullException("first");
  1602. if (second == null)
  1603. throw new ArgumentNullException("second");
  1604. if (comparer == null)
  1605. throw new ArgumentNullException("comparer");
  1606. return s_impl.SequenceEqual<TSource>(first, second, comparer);
  1607. }
  1608. /// <summary>
  1609. /// Determines whether an observable and enumerable sequence are equal by comparing the elements pairwise.
  1610. /// </summary>
  1611. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1612. /// <param name="first">First observable sequence to compare.</param>
  1613. /// <param name="second">Second observable sequence to compare.</param>
  1614. /// <returns>An observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the default equality comparer for their type.</returns>
  1615. /// <exception cref="ArgumentNullException"><paramref name="first"/> or <paramref name="second"/> is null.</exception>
  1616. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1617. public static IObservable<bool> SequenceEqual<TSource>(this IObservable<TSource> first, IEnumerable<TSource> second)
  1618. {
  1619. if (first == null)
  1620. throw new ArgumentNullException("first");
  1621. if (second == null)
  1622. throw new ArgumentNullException("second");
  1623. return s_impl.SequenceEqual<TSource>(first, second);
  1624. }
  1625. /// <summary>
  1626. /// Determines whether an observable and enumerable sequence are equal by comparing the elements pairwise using a specified equality comparer.
  1627. /// </summary>
  1628. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1629. /// <param name="first">First observable sequence to compare.</param>
  1630. /// <param name="second">Second observable sequence to compare.</param>
  1631. /// <param name="comparer">Comparer used to compare elements of both sequences.</param>
  1632. /// <returns>An observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the specified equality comparer.</returns>
  1633. /// <exception cref="ArgumentNullException"><paramref name="first"/> or <paramref name="second"/> or <paramref name="comparer"/> is null.</exception>
  1634. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1635. public static IObservable<bool> SequenceEqual<TSource>(this IObservable<TSource> first, IEnumerable<TSource> second, IEqualityComparer<TSource> comparer)
  1636. {
  1637. if (first == null)
  1638. throw new ArgumentNullException("first");
  1639. if (second == null)
  1640. throw new ArgumentNullException("second");
  1641. if (comparer == null)
  1642. throw new ArgumentNullException("comparer");
  1643. return s_impl.SequenceEqual<TSource>(first, second, comparer);
  1644. }
  1645. #endregion
  1646. #region + SingleAsync +
  1647. /// <summary>
  1648. /// Returns the only element of an observable sequence, and reports an exception if there is not exactly one element in the observable sequence.
  1649. /// </summary>
  1650. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1651. /// <param name="source">Source observable sequence.</param>
  1652. /// <returns>Sequence containing the single element in the observable sequence.</returns>
  1653. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1654. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence contains more than one element. -or- The source sequence is empty.</exception>
  1655. public static IObservable<TSource> SingleAsync<TSource>(this IObservable<TSource> source)
  1656. {
  1657. if (source == null)
  1658. throw new ArgumentNullException("source");
  1659. return s_impl.SingleAsync<TSource>(source);
  1660. }
  1661. /// <summary>
  1662. /// Returns the only element of an observable sequence that satisfies the condition in the predicate, and reports an exception if there is not exactly one element in the observable sequence.
  1663. /// </summary>
  1664. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1665. /// <param name="source">Source observable sequence.</param>
  1666. /// <param name="predicate">A predicate function to evaluate for elements in the source sequence.</param>
  1667. /// <returns>Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.</returns>
  1668. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  1669. /// <exception cref="InvalidOperationException">(Asynchronous) No element satisfies the condition in the predicate. -or- More than one element satisfies the condition in the predicate. -or- The source sequence is empty.</exception>
  1670. public static IObservable<TSource> SingleAsync<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  1671. {
  1672. if (source == null)
  1673. throw new ArgumentNullException("source");
  1674. if (predicate == null)
  1675. throw new ArgumentNullException("predicate");
  1676. return s_impl.SingleAsync<TSource>(source, predicate);
  1677. }
  1678. #endregion
  1679. #region + SingleOrDefaultAsync +
  1680. /// <summary>
  1681. /// Returns the only element of an observable sequence, or a default value if the observable sequence is empty; this method reports an exception if there is more than one element in the observable sequence.
  1682. /// </summary>
  1683. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1684. /// <param name="source">Source observable sequence.</param>
  1685. /// <returns>Sequence containing the single element in the observable sequence, or a default value if no such element exists.</returns>
  1686. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1687. /// <exception cref="InvalidOperationException">(Asynchronous) The source sequence contains more than one element.</exception>
  1688. public static IObservable<TSource> SingleOrDefaultAsync<TSource>(this IObservable<TSource> source)
  1689. {
  1690. if (source == null)
  1691. throw new ArgumentNullException("source");
  1692. return s_impl.SingleOrDefaultAsync<TSource>(source);
  1693. }
  1694. /// <summary>
  1695. /// Returns the only element of an observable sequence that matches the predicate, or a default value if no such element exists; this method reports an exception if there is more than one element in the observable sequence.
  1696. /// </summary>
  1697. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1698. /// <param name="source">Source observable sequence.</param>
  1699. /// <param name="predicate">A predicate function to evaluate for elements in the source sequence.</param>
  1700. /// <returns>Sequence containing the single element in the observable sequence that satisfies the condition in the predicate, or a default value if no such element exists.</returns>
  1701. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
  1702. /// <exception cref="InvalidOperationException">(Asynchronous) The sequence contains more than one element that satisfies the condition in the predicate.</exception>
  1703. public static IObservable<TSource> SingleOrDefaultAsync<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
  1704. {
  1705. if (source == null)
  1706. throw new ArgumentNullException("source");
  1707. if (predicate == null)
  1708. throw new ArgumentNullException("predicate");
  1709. return s_impl.SingleOrDefaultAsync<TSource>(source, predicate);
  1710. }
  1711. #endregion
  1712. #region + Sum +
  1713. /// <summary>
  1714. /// Computes the sum of a sequence of <see cref="T:System.Double" /> values.
  1715. /// </summary>
  1716. /// <param name="source">A sequence of <see cref="T:System.Double" /> values to calculate the sum of.</param>
  1717. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1718. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1719. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1720. public static IObservable<double> Sum(this IObservable<double> source)
  1721. {
  1722. if (source == null)
  1723. throw new ArgumentNullException("source");
  1724. return s_impl.Sum(source);
  1725. }
  1726. /// <summary>
  1727. /// Computes the sum of a sequence of <see cref="T:System.Single" /> values.
  1728. /// </summary>
  1729. /// <param name="source">A sequence of <see cref="T:System.Single" /> values to calculate the sum of.</param>
  1730. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1731. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1732. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1733. public static IObservable<float> Sum(this IObservable<float> source)
  1734. {
  1735. if (source == null)
  1736. throw new ArgumentNullException("source");
  1737. return s_impl.Sum(source);
  1738. }
  1739. /// <summary>
  1740. /// Computes the sum of a sequence of <see cref="T:System.Decimal" /> values.
  1741. /// </summary>
  1742. /// <param name="source">A sequence of <see cref="T:System.Decimal" /> values to calculate the sum of.</param>
  1743. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1744. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1745. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Decimal.MaxValue"/>.</exception>
  1746. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1747. public static IObservable<decimal> Sum(this IObservable<decimal> source)
  1748. {
  1749. if (source == null)
  1750. throw new ArgumentNullException("source");
  1751. return s_impl.Sum(source);
  1752. }
  1753. /// <summary>
  1754. /// Computes the sum of a sequence of <see cref="T:System.Int32" /> values.
  1755. /// </summary>
  1756. /// <param name="source">A sequence of <see cref="T:System.Int32" /> values to calculate the sum of.</param>
  1757. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1758. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1759. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Int32.MaxValue"/>.</exception>
  1760. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1761. public static IObservable<int> Sum(this IObservable<int> source)
  1762. {
  1763. if (source == null)
  1764. throw new ArgumentNullException("source");
  1765. return s_impl.Sum(source);
  1766. }
  1767. /// <summary>
  1768. /// Computes the sum of a sequence of <see cref="T:System.Int64" /> values.
  1769. /// </summary>
  1770. /// <param name="source">A sequence of <see cref="T:System.Int64" /> values to calculate the sum of.</param>
  1771. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1772. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1773. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  1774. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1775. public static IObservable<long> Sum(this IObservable<long> source)
  1776. {
  1777. if (source == null)
  1778. throw new ArgumentNullException("source");
  1779. return s_impl.Sum(source);
  1780. }
  1781. /// <summary>
  1782. /// Computes the sum of a sequence of nullable <see cref="T:System.Double" /> values.
  1783. /// </summary>
  1784. /// <param name="source">A sequence of nullable <see cref="T:System.Double" /> values to calculate the sum of.</param>
  1785. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1786. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1787. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1788. public static IObservable<double?> Sum(this IObservable<double?> source)
  1789. {
  1790. if (source == null)
  1791. throw new ArgumentNullException("source");
  1792. return s_impl.Sum(source);
  1793. }
  1794. /// <summary>
  1795. /// Computes the sum of a sequence of nullable <see cref="T:System.Single" /> values.
  1796. /// </summary>
  1797. /// <param name="source">A sequence of nullable <see cref="T:System.Single" /> values to calculate the sum of.</param>
  1798. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1799. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1800. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1801. public static IObservable<float?> Sum(this IObservable<float?> source)
  1802. {
  1803. if (source == null)
  1804. throw new ArgumentNullException("source");
  1805. return s_impl.Sum(source);
  1806. }
  1807. /// <summary>
  1808. /// Computes the sum of a sequence of nullable <see cref="T:System.Decimal" /> values.
  1809. /// </summary>
  1810. /// <param name="source">A sequence of nullable <see cref="T:System.Decimal" /> values to calculate the sum of.</param>
  1811. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1812. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1813. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Decimal.MaxValue"/>.</exception>
  1814. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1815. public static IObservable<decimal?> Sum(this IObservable<decimal?> source)
  1816. {
  1817. if (source == null)
  1818. throw new ArgumentNullException("source");
  1819. return s_impl.Sum(source);
  1820. }
  1821. /// <summary>
  1822. /// Computes the sum of a sequence of nullable <see cref="T:System.Int32" /> values.
  1823. /// </summary>
  1824. /// <param name="source">A sequence of nullable <see cref="T:System.Int32" /> values to calculate the sum of.</param>
  1825. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1826. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1827. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Int32.MaxValue"/>.</exception>
  1828. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1829. public static IObservable<int?> Sum(this IObservable<int?> source)
  1830. {
  1831. if (source == null)
  1832. throw new ArgumentNullException("source");
  1833. return s_impl.Sum(source);
  1834. }
  1835. /// <summary>
  1836. /// Computes the sum of a sequence of nullable <see cref="T:System.Int64" /> values.
  1837. /// </summary>
  1838. /// <param name="source">A sequence of nullable <see cref="T:System.Int64" /> values to calculate the sum of.</param>
  1839. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1840. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  1841. /// <exception cref="OverflowException">(Asynchronous) The sum of the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  1842. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1843. public static IObservable<long?> Sum(this IObservable<long?> source)
  1844. {
  1845. if (source == null)
  1846. throw new ArgumentNullException("source");
  1847. return s_impl.Sum(source);
  1848. }
  1849. /// <summary>
  1850. /// Computes the sum of a sequence of <see cref="T:System.Double" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1851. /// </summary>
  1852. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1853. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1854. /// <param name="selector">A transform function to apply to each element.</param>
  1855. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1856. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1857. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1858. public static IObservable<double> Sum<TSource>(this IObservable<TSource> source, Func<TSource, double> selector)
  1859. {
  1860. if (source == null)
  1861. throw new ArgumentNullException("source");
  1862. if (selector == null)
  1863. throw new ArgumentNullException("selector");
  1864. return s_impl.Sum<TSource>(source, selector);
  1865. }
  1866. /// <summary>
  1867. /// Computes the sum of a sequence of <see cref="T:System.Single" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1868. /// </summary>
  1869. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1870. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1871. /// <param name="selector">A transform function to apply to each element.</param>
  1872. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1873. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1874. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1875. public static IObservable<float> Sum<TSource>(this IObservable<TSource> source, Func<TSource, float> selector)
  1876. {
  1877. if (source == null)
  1878. throw new ArgumentNullException("source");
  1879. if (selector == null)
  1880. throw new ArgumentNullException("selector");
  1881. return s_impl.Sum<TSource>(source, selector);
  1882. }
  1883. /// <summary>
  1884. /// Computes the sum of a sequence of <see cref="T:System.Decimal" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1885. /// </summary>
  1886. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1887. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1888. /// <param name="selector">A transform function to apply to each element.</param>
  1889. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1890. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1891. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Decimal.MaxValue"/>.</exception>
  1892. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1893. public static IObservable<decimal> Sum<TSource>(this IObservable<TSource> source, Func<TSource, decimal> selector)
  1894. {
  1895. if (source == null)
  1896. throw new ArgumentNullException("source");
  1897. if (selector == null)
  1898. throw new ArgumentNullException("selector");
  1899. return s_impl.Sum<TSource>(source, selector);
  1900. }
  1901. /// <summary>
  1902. /// Computes the sum of a sequence of <see cref="T:System.Int32" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1903. /// </summary>
  1904. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1905. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1906. /// <param name="selector">A transform function to apply to each element.</param>
  1907. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1908. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1909. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Int32.MaxValue"/>.</exception>
  1910. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1911. public static IObservable<int> Sum<TSource>(this IObservable<TSource> source, Func<TSource, int> selector)
  1912. {
  1913. if (source == null)
  1914. throw new ArgumentNullException("source");
  1915. if (selector == null)
  1916. throw new ArgumentNullException("selector");
  1917. return s_impl.Sum<TSource>(source, selector);
  1918. }
  1919. /// <summary>
  1920. /// Computes the sum of a sequence of <see cref="T:System.Int64" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1921. /// </summary>
  1922. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1923. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1924. /// <param name="selector">A transform function to apply to each element.</param>
  1925. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1926. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1927. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  1928. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1929. public static IObservable<long> Sum<TSource>(this IObservable<TSource> source, Func<TSource, long> selector)
  1930. {
  1931. if (source == null)
  1932. throw new ArgumentNullException("source");
  1933. if (selector == null)
  1934. throw new ArgumentNullException("selector");
  1935. return s_impl.Sum<TSource>(source, selector);
  1936. }
  1937. /// <summary>
  1938. /// Computes the sum of a sequence of nullable <see cref="T:System.Double" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1939. /// </summary>
  1940. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1941. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1942. /// <param name="selector">A transform function to apply to each element.</param>
  1943. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1944. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1945. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1946. public static IObservable<double?> Sum<TSource>(this IObservable<TSource> source, Func<TSource, double?> selector)
  1947. {
  1948. if (source == null)
  1949. throw new ArgumentNullException("source");
  1950. if (selector == null)
  1951. throw new ArgumentNullException("selector");
  1952. return s_impl.Sum<TSource>(source, selector);
  1953. }
  1954. /// <summary>
  1955. /// Computes the sum of a sequence of nullable <see cref="T:System.Single" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1956. /// </summary>
  1957. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1958. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1959. /// <param name="selector">A transform function to apply to each element.</param>
  1960. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1961. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1962. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1963. public static IObservable<float?> Sum<TSource>(this IObservable<TSource> source, Func<TSource, float?> selector)
  1964. {
  1965. if (source == null)
  1966. throw new ArgumentNullException("source");
  1967. if (selector == null)
  1968. throw new ArgumentNullException("selector");
  1969. return s_impl.Sum<TSource>(source, selector);
  1970. }
  1971. /// <summary>
  1972. /// Computes the sum of a sequence of nullable <see cref="T:System.Decimal" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1973. /// </summary>
  1974. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1975. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1976. /// <param name="selector">A transform function to apply to each element.</param>
  1977. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1978. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1979. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Decimal.MaxValue"/>.</exception>
  1980. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1981. public static IObservable<decimal?> Sum<TSource>(this IObservable<TSource> source, Func<TSource, decimal?> selector)
  1982. {
  1983. if (source == null)
  1984. throw new ArgumentNullException("source");
  1985. if (selector == null)
  1986. throw new ArgumentNullException("selector");
  1987. return s_impl.Sum<TSource>(source, selector);
  1988. }
  1989. /// <summary>
  1990. /// Computes the sum of a sequence of nullable <see cref="T:System.Int32" /> values that are obtained by invoking a transform function on each element of the input sequence.
  1991. /// </summary>
  1992. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  1993. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  1994. /// <param name="selector">A transform function to apply to each element.</param>
  1995. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  1996. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  1997. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Int32.MaxValue"/>.</exception>
  1998. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  1999. public static IObservable<int?> Sum<TSource>(this IObservable<TSource> source, Func<TSource, int?> selector)
  2000. {
  2001. if (source == null)
  2002. throw new ArgumentNullException("source");
  2003. if (selector == null)
  2004. throw new ArgumentNullException("selector");
  2005. return s_impl.Sum<TSource>(source, selector);
  2006. }
  2007. /// <summary>
  2008. /// Computes the sum of a sequence of nullable <see cref="T:System.Int64" /> values that are obtained by invoking a transform function on each element of the input sequence.
  2009. /// </summary>
  2010. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2011. /// <param name="source">A sequence of values that are used to calculate a sum.</param>
  2012. /// <param name="selector">A transform function to apply to each element.</param>
  2013. /// <returns>An observable sequence containing a single element with the sum of the values in the source sequence.</returns>
  2014. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  2015. /// <exception cref="OverflowException">(Asynchronous) The sum of the projected values for the elements in the source sequence is larger than <see cref="M:System.Int64.MaxValue"/>.</exception>
  2016. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2017. public static IObservable<long?> Sum<TSource>(this IObservable<TSource> source, Func<TSource, long?> selector)
  2018. {
  2019. if (source == null)
  2020. throw new ArgumentNullException("source");
  2021. if (selector == null)
  2022. throw new ArgumentNullException("selector");
  2023. return s_impl.Sum<TSource>(source, selector);
  2024. }
  2025. #endregion
  2026. #region + ToArray +
  2027. /// <summary>
  2028. /// Creates an array from an observable sequence.
  2029. /// </summary>
  2030. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2031. /// <param name="source">The source observable sequence to get an array of elements for.</param>
  2032. /// <returns>An observable sequence containing a single element with an array containing all the elements of the source sequence.</returns>
  2033. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  2034. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2035. public static IObservable<TSource[]> ToArray<TSource>(this IObservable<TSource> source)
  2036. {
  2037. if (source == null)
  2038. throw new ArgumentNullException("source");
  2039. return s_impl.ToArray<TSource>(source);
  2040. }
  2041. #endregion
  2042. #region + ToDictionary +
  2043. /// <summary>
  2044. /// Creates a dictionary from an observable sequence according to a specified key selector function.
  2045. /// </summary>
  2046. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2047. /// <typeparam name="TKey">The type of the dictionary key computed for each element in the source sequence.</typeparam>
  2048. /// <param name="source">An observable sequence to create a dictionary for.</param>
  2049. /// <param name="keySelector">A function to extract a key from each element.</param>
  2050. /// <returns>An observable sequence containing a single element with a dictionary mapping unique key values onto the corresponding source sequence's element.</returns>
  2051. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> is null.</exception>
  2052. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2053. public static IObservable<IDictionary<TKey, TSource>> ToDictionary<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector)
  2054. {
  2055. if (source == null)
  2056. throw new ArgumentNullException("source");
  2057. if (keySelector == null)
  2058. throw new ArgumentNullException("keySelector");
  2059. return s_impl.ToDictionary<TSource, TKey>(source, keySelector);
  2060. }
  2061. /// <summary>
  2062. /// Creates a dictionary from an observable sequence according to a specified key selector function, and a comparer.
  2063. /// </summary>
  2064. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2065. /// <typeparam name="TKey">The type of the dictionary key computed for each element in the source sequence.</typeparam>
  2066. /// <param name="source">An observable sequence to create a dictionary for.</param>
  2067. /// <param name="keySelector">A function to extract a key from each element.</param>
  2068. /// <param name="comparer">An equality comparer to compare keys.</param>
  2069. /// <returns>An observable sequence containing a single element with a dictionary mapping unique key values onto the corresponding source sequence's element.</returns>
  2070. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="comparer"/> is null.</exception>
  2071. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2072. public static IObservable<IDictionary<TKey, TSource>> ToDictionary<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
  2073. {
  2074. if (source == null)
  2075. throw new ArgumentNullException("source");
  2076. if (keySelector == null)
  2077. throw new ArgumentNullException("keySelector");
  2078. if (comparer == null)
  2079. throw new ArgumentNullException("comparer");
  2080. return s_impl.ToDictionary<TSource, TKey>(source, keySelector, comparer);
  2081. }
  2082. /// <summary>
  2083. /// Creates a dictionary from an observable sequence according to a specified key selector function, and an element selector function.
  2084. /// </summary>
  2085. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2086. /// <typeparam name="TKey">The type of the dictionary key computed for each element in the source sequence.</typeparam>
  2087. /// <typeparam name="TElement">The type of the dictionary value computed for each element in the source sequence.</typeparam>
  2088. /// <param name="source">An observable sequence to create a dictionary for.</param>
  2089. /// <param name="keySelector">A function to extract a key from each element.</param>
  2090. /// <param name="elementSelector">A transform function to produce a result element value from each element.</param>
  2091. /// <returns>An observable sequence containing a single element with a dictionary mapping unique key values onto the corresponding source sequence's element.</returns>
  2092. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> is null.</exception>
  2093. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2094. public static IObservable<IDictionary<TKey, TElement>> ToDictionary<TSource, TKey, TElement>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
  2095. {
  2096. if (source == null)
  2097. throw new ArgumentNullException("source");
  2098. if (keySelector == null)
  2099. throw new ArgumentNullException("keySelector");
  2100. if (elementSelector == null)
  2101. throw new ArgumentNullException("elementSelector");
  2102. return s_impl.ToDictionary<TSource, TKey, TElement>(source, keySelector, elementSelector);
  2103. }
  2104. /// <summary>
  2105. /// Creates a dictionary from an observable sequence according to a specified key selector function, a comparer, and an element selector function.
  2106. /// </summary>
  2107. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2108. /// <typeparam name="TKey">The type of the dictionary key computed for each element in the source sequence.</typeparam>
  2109. /// <typeparam name="TElement">The type of the dictionary value computed for each element in the source sequence.</typeparam>
  2110. /// <param name="source">An observable sequence to create a dictionary for.</param>
  2111. /// <param name="keySelector">A function to extract a key from each element.</param>
  2112. /// <param name="elementSelector">A transform function to produce a result element value from each element.</param>
  2113. /// <param name="comparer">An equality comparer to compare keys.</param>
  2114. /// <returns>An observable sequence containing a single element with a dictionary mapping unique key values onto the corresponding source sequence's element.</returns>
  2115. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> or <paramref name="comparer"/> is null.</exception>
  2116. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2117. public static IObservable<IDictionary<TKey, TElement>> ToDictionary<TSource, TKey, TElement>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
  2118. {
  2119. if (source == null)
  2120. throw new ArgumentNullException("source");
  2121. if (keySelector == null)
  2122. throw new ArgumentNullException("keySelector");
  2123. if (elementSelector == null)
  2124. throw new ArgumentNullException("elementSelector");
  2125. if (comparer == null)
  2126. throw new ArgumentNullException("comparer");
  2127. return s_impl.ToDictionary<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
  2128. }
  2129. #endregion
  2130. #region + ToList +
  2131. /// <summary>
  2132. /// Creates a list from an observable sequence.
  2133. /// </summary>
  2134. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2135. /// <param name="source">The source observable sequence to get a list of elements for.</param>
  2136. /// <returns>An observable sequence containing a single element with a list containing all the elements of the source sequence.</returns>
  2137. /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
  2138. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2139. public static IObservable<IList<TSource>> ToList<TSource>(this IObservable<TSource> source)
  2140. {
  2141. if (source == null)
  2142. throw new ArgumentNullException("source");
  2143. return s_impl.ToList<TSource>(source);
  2144. }
  2145. #endregion
  2146. #region + ToLookup +
  2147. /// <summary>
  2148. /// Creates a lookup from an observable sequence according to a specified key selector function.
  2149. /// </summary>
  2150. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2151. /// <typeparam name="TKey">The type of the lookup key computed for each element in the source sequence.</typeparam>
  2152. /// <param name="source">An observable sequence to create a lookup for.</param>
  2153. /// <param name="keySelector">A function to extract a key from each element.</param>
  2154. /// <returns>An observable sequence containing a single element with a lookup mapping unique key values onto the corresponding source sequence's elements.</returns>
  2155. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> is null.</exception>
  2156. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2157. public static IObservable<ILookup<TKey, TSource>> ToLookup<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector)
  2158. {
  2159. if (source == null)
  2160. throw new ArgumentNullException("source");
  2161. if (keySelector == null)
  2162. throw new ArgumentNullException("keySelector");
  2163. return s_impl.ToLookup<TSource, TKey>(source, keySelector);
  2164. }
  2165. /// <summary>
  2166. /// Creates a lookup from an observable sequence according to a specified key selector function, and a comparer.
  2167. /// </summary>
  2168. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2169. /// <typeparam name="TKey">The type of the lookup key computed for each element in the source sequence.</typeparam>
  2170. /// <param name="source">An observable sequence to create a lookup for.</param>
  2171. /// <param name="keySelector">A function to extract a key from each element.</param>
  2172. /// <param name="comparer">An equality comparer to compare keys.</param>
  2173. /// <returns>An observable sequence containing a single element with a lookup mapping unique key values onto the corresponding source sequence's elements.</returns>
  2174. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="comparer"/> is null.</exception>
  2175. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2176. public static IObservable<ILookup<TKey, TSource>> ToLookup<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
  2177. {
  2178. if (source == null)
  2179. throw new ArgumentNullException("source");
  2180. if (keySelector == null)
  2181. throw new ArgumentNullException("keySelector");
  2182. if (comparer == null)
  2183. throw new ArgumentNullException("comparer");
  2184. return s_impl.ToLookup<TSource, TKey>(source, keySelector, comparer);
  2185. }
  2186. /// <summary>
  2187. /// Creates a lookup from an observable sequence according to a specified key selector function, and an element selector function.
  2188. /// </summary>
  2189. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2190. /// <typeparam name="TKey">The type of the lookup key computed for each element in the source sequence.</typeparam>
  2191. /// <typeparam name="TElement">The type of the lookup value computed for each element in the source sequence.</typeparam>
  2192. /// <param name="source">An observable sequence to create a lookup for.</param>
  2193. /// <param name="keySelector">A function to extract a key from each element.</param>
  2194. /// <param name="elementSelector">A transform function to produce a result element value from each element.</param>
  2195. /// <returns>An observable sequence containing a single element with a lookup mapping unique key values onto the corresponding source sequence's elements.</returns>
  2196. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> is null.</exception>
  2197. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2198. public static IObservable<ILookup<TKey, TElement>> ToLookup<TSource, TKey, TElement>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
  2199. {
  2200. if (source == null)
  2201. throw new ArgumentNullException("source");
  2202. if (keySelector == null)
  2203. throw new ArgumentNullException("keySelector");
  2204. if (elementSelector == null)
  2205. throw new ArgumentNullException("elementSelector");
  2206. return s_impl.ToLookup<TSource, TKey, TElement>(source, keySelector, elementSelector);
  2207. }
  2208. /// <summary>
  2209. /// Creates a lookup from an observable sequence according to a specified key selector function, a comparer, and an element selector function.
  2210. /// </summary>
  2211. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  2212. /// <typeparam name="TKey">The type of the lookup key computed for each element in the source sequence.</typeparam>
  2213. /// <typeparam name="TElement">The type of the lookup value computed for each element in the source sequence.</typeparam>
  2214. /// <param name="source">An observable sequence to create a lookup for.</param>
  2215. /// <param name="keySelector">A function to extract a key from each element.</param>
  2216. /// <param name="elementSelector">A transform function to produce a result element value from each element.</param>
  2217. /// <param name="comparer">An equality comparer to compare keys.</param>
  2218. /// <returns>An observable sequence containing a single element with a lookup mapping unique key values onto the corresponding source sequence's elements.</returns>
  2219. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> or <paramref name="comparer"/> is null.</exception>
  2220. /// <remarks>The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior.</remarks>
  2221. public static IObservable<ILookup<TKey, TElement>> ToLookup<TSource, TKey, TElement>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
  2222. {
  2223. if (source == null)
  2224. throw new ArgumentNullException("source");
  2225. if (keySelector == null)
  2226. throw new ArgumentNullException("keySelector");
  2227. if (elementSelector == null)
  2228. throw new ArgumentNullException("elementSelector");
  2229. if (comparer == null)
  2230. throw new ArgumentNullException("comparer");
  2231. return s_impl.ToLookup<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
  2232. }
  2233. #endregion
  2234. }
  2235. }