Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Linq/Reactive/Linq/Observable.StandardSequenceOperators.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 using System.Collections.Generic;
4 using System.Reactive.Concurrency;
5
6 #if !NO_TPL
7 using System.Reactive.Threading.Tasks; // needed for doc comments
8 using System.Threading;
9 using System.Threading.Tasks;
10 #endif
11
12 namespace System.Reactive.Linq
13 {
14 public static partial class Observable
15 {
16 #region + Cast +
17
18 /// <summary>
19 /// Converts the elements of an observable sequence to the specified type.
20 /// </summary>
21 /// <typeparam name="TResult">The type to convert the elements in the source sequence to.</typeparam>
22 /// <param name="source">The observable sequence that contains the elements to be converted.</param>
23 /// <returns>An observable sequence that contains each element of the source sequence converted to the specified type.</returns>
24 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
25 public static IObservable<TResult> Cast<TResult>(this IObservable<object> source)
26 {
27 if (source == null)
28 throw new ArgumentNullException("source");
29
30 return s_impl.Cast<TResult>(source);
31 }
32
33 #endregion
34
35 #region + DefaultIfEmpty +
36
37 /// <summary>
38 /// Returns the elements of the specified sequence or the type parameter's default value in a singleton sequence if the sequence is empty.
39 /// </summary>
40 /// <typeparam name="TSource">The type of the elements in the source sequence (if any), whose default value will be taken if the sequence is empty.</typeparam>
41 /// <param name="source">The sequence to return a default value for if it is empty.</param>
42 /// <returns>An observable sequence that contains the default value for the TSource type if the source is empty; otherwise, the elements of the source itself.</returns>
43 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
44 public static IObservable<TSource> DefaultIfEmpty<TSource>(this IObservable<TSource> source)
45 {
46 if (source == null)
47 throw new ArgumentNullException("source");
48
49 return s_impl.DefaultIfEmpty<TSource>(source);
50 }
51
52 /// <summary>
53 /// Returns the elements of the specified sequence or the specified value in a singleton sequence if the sequence is empty.
54 /// </summary>
55 /// <typeparam name="TSource">The type of the elements in the source sequence (if any), and the specified default value which will be taken if the sequence is empty.</typeparam>
56 /// <param name="source">The sequence to return the specified value for if it is empty.</param>
57 /// <param name="defaultValue">The value to return if the sequence is empty.</param>
58 /// <returns>An observable sequence that contains the specified default value if the source is empty; otherwise, the elements of the source itself.</returns>
59 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
60 public static IObservable<TSource> DefaultIfEmpty<TSource>(this IObservable<TSource> source, TSource defaultValue)
61 {
62 if (source == null)
63 throw new ArgumentNullException("source");
64
65 return s_impl.DefaultIfEmpty<TSource>(source, defaultValue);
66 }
67
68 #endregion
69
70 #region + Distinct +
71
72 /// <summary>
73 /// Returns an observable sequence that contains only distinct elements.
74 /// </summary>
75 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
76 /// <param name="source">An observable sequence to retain distinct elements for.</param>
77 /// <returns>An observable sequence only containing the distinct elements from the source sequence.</returns>
78 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
79 /// <remarks>Usage of this operator should be considered carefully due to the maintenance of an internal lookup structure which can grow large.</remarks>
80 public static IObservable<TSource> Distinct<TSource>(this IObservable<TSource> source)
81 {
82 if (source == null)
83 throw new ArgumentNullException("source");
84
85 return s_impl.Distinct<TSource>(source);
86 }
87
88 /// <summary>
89 /// Returns an observable sequence that contains only distinct elements according to the comparer.
90 /// </summary>
91 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
92 /// <param name="source">An observable sequence to retain distinct elements for.</param>
93 /// <param name="comparer">Equality comparer for source elements.</param>
94 /// <returns>An observable sequence only containing the distinct elements from the source sequence.</returns>
95 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="comparer"/> is null.</exception>
96 /// <remarks>Usage of this operator should be considered carefully due to the maintenance of an internal lookup structure which can grow large.</remarks>
97 public static IObservable<TSource> Distinct<TSource>(this IObservable<TSource> source, IEqualityComparer<TSource> comparer)
98 {
99 if (source == null)
100 throw new ArgumentNullException("source");
101 if (comparer == null)
102 throw new ArgumentNullException("comparer");
103
104 return s_impl.Distinct<TSource>(source, comparer);
105 }
106
107 /// <summary>
108 /// Returns an observable sequence that contains only distinct elements according to the keySelector.
109 /// </summary>
110 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
111 /// <typeparam name="TKey">The type of the discriminator key computed for each element in the source sequence.</typeparam>
112 /// <param name="source">An observable sequence to retain distinct elements for.</param>
113 /// <param name="keySelector">A function to compute the comparison key for each element.</param>
114 /// <returns>An observable sequence only containing the distinct elements, based on a computed key value, from the source sequence.</returns>
115 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> is null.</exception>
116 /// <remarks>Usage of this operator should be considered carefully due to the maintenance of an internal lookup structure which can grow large.</remarks>
117 public static IObservable<TSource> Distinct<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector)
118 {
119 if (source == null)
120 throw new ArgumentNullException("source");
121 if (keySelector == null)
122 throw new ArgumentNullException("keySelector");
123
124 return s_impl.Distinct<TSource, TKey>(source, keySelector);
125 }
126
127 /// <summary>
128 /// Returns an observable sequence that contains only distinct elements according to the keySelector and the comparer.
129 /// </summary>
130 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
131 /// <typeparam name="TKey">The type of the discriminator key computed for each element in the source sequence.</typeparam>
132 /// <param name="source">An observable sequence to retain distinct elements for.</param>
133 /// <param name="keySelector">A function to compute the comparison key for each element.</param>
134 /// <param name="comparer">Equality comparer for source elements.</param>
135 /// <returns>An observable sequence only containing the distinct elements, based on a computed key value, from the source sequence.</returns>
136 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="comparer"/> is null.</exception>
137 /// <remarks>Usage of this operator should be considered carefully due to the maintenance of an internal lookup structure which can grow large.</remarks>
138 public static IObservable<TSource> Distinct<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
139 {
140 if (source == null)
141 throw new ArgumentNullException("source");
142 if (keySelector == null)
143 throw new ArgumentNullException("keySelector");
144 if (comparer == null)
145 throw new ArgumentNullException("comparer");
146
147 return s_impl.Distinct<TSource, TKey>(source, keySelector, comparer);
148 }
149
150 #endregion
151
152 #region + GroupBy +
153
154 /// <summary>
155 /// Groups the elements of an observable sequence according to a specified key selector function.
156 /// </summary>
157 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
158 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
159 /// <param name="source">An observable sequence whose elements to group.</param>
160 /// <param name="keySelector">A function to extract the key for each element.</param>
161 /// <returns>A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.</returns>
162 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> is null.</exception>
163 public static IObservable<IGroupedObservable<TKey, TSource>> GroupBy<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector)
164 {
165 if (source == null)
166 throw new ArgumentNullException("source");
167 if (keySelector == null)
168 throw new ArgumentNullException("keySelector");
169
170 return s_impl.GroupBy<TSource, TKey>(source, keySelector);
171 }
172
173 /// <summary>
174 /// Groups the elements of an observable sequence according to a specified key selector function and comparer.
175 /// </summary>
176 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
177 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
178 /// <param name="source">An observable sequence whose elements to group.</param>
179 /// <param name="keySelector">A function to extract the key for each element.</param>
180 /// <param name="comparer">An equality comparer to compare keys with.</param>
181 /// <returns>A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.</returns>
182 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="comparer"/> is null.</exception>
183 public static IObservable<IGroupedObservable<TKey, TSource>> GroupBy<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
184 {
185 if (source == null)
186 throw new ArgumentNullException("source");
187 if (keySelector == null)
188 throw new ArgumentNullException("keySelector");
189 if (comparer == null)
190 throw new ArgumentNullException("comparer");
191
192 return s_impl.GroupBy<TSource, TKey>(source, keySelector, comparer);
193 }
194
195 /// <summary>
196 /// Groups the elements of an observable sequence and selects the resulting elements by using a specified function.
197 /// </summary>
198 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
199 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
200 /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
201 /// <param name="source">An observable sequence whose elements to group.</param>
202 /// <param name="keySelector">A function to extract the key for each element.</param>
203 /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
204 /// <returns>A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.</returns>
205 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> is null.</exception>
206 public static IObservable<IGroupedObservable<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
207 {
208 if (source == null)
209 throw new ArgumentNullException("source");
210 if (keySelector == null)
211 throw new ArgumentNullException("keySelector");
212 if (elementSelector == null)
213 throw new ArgumentNullException("elementSelector");
214
215 return s_impl.GroupBy<TSource, TKey, TElement>(source, keySelector, elementSelector);
216 }
217
218 /// <summary>
219 /// Groups the elements of an observable sequence according to a specified key selector function and comparer and selects the resulting elements by using a specified function.
220 /// </summary>
221 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
222 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
223 /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
224 /// <param name="source">An observable sequence whose elements to group.</param>
225 /// <param name="keySelector">A function to extract the key for each element.</param>
226 /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
227 /// <param name="comparer">An equality comparer to compare keys with.</param>
228 /// <returns>A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.</returns>
229 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> or <paramref name="comparer"/> is null.</exception>
230 public static IObservable<IGroupedObservable<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer)
231 {
232 if (source == null)
233 throw new ArgumentNullException("source");
234 if (keySelector == null)
235 throw new ArgumentNullException("keySelector");
236 if (elementSelector == null)
237 throw new ArgumentNullException("elementSelector");
238 if (comparer == null)
239 throw new ArgumentNullException("comparer");
240
241 return s_impl.GroupBy<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer);
242 }
243
244 /// <summary>
245 /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function.
246 /// </summary>
247 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
248 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
249 /// <param name="source">An observable sequence whose elements to group.</param>
250 /// <param name="keySelector">A function to extract the key for each element.</param>
251 /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
252 /// <returns>A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.</returns>
253 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> is null.</exception>
254 /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
255 public static IObservable<IGroupedObservable<TKey, TSource>> GroupBy<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, int capacity)
256 {
257 if (source == null)
258 throw new ArgumentNullException("source");
259 if (keySelector == null)
260 throw new ArgumentNullException("keySelector");
261 if (capacity < 0)
262 throw new ArgumentOutOfRangeException("capacity");
263
264 return s_impl.GroupBy<TSource, TKey>(source, keySelector, capacity);
265 }
266
267 /// <summary>
268 /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function and comparer.
269 /// </summary>
270 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
271 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
272 /// <param name="source">An observable sequence whose elements to group.</param>
273 /// <param name="keySelector">A function to extract the key for each element.</param>
274 /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
275 /// <param name="comparer">An equality comparer to compare keys with.</param>
276 /// <returns>A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.</returns>
277 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="comparer"/> is null.</exception>
278 /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
279 public static IObservable<IGroupedObservable<TKey, TSource>> GroupBy<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, int capacity, IEqualityComparer<TKey> comparer)
280 {
281 if (source == null)
282 throw new ArgumentNullException("source");
283 if (keySelector == null)
284 throw new ArgumentNullException("keySelector");
285 if (capacity < 0)
286 throw new ArgumentOutOfRangeException("capacity");
287 if (comparer == null)
288 throw new ArgumentNullException("comparer");
289
290 return s_impl.GroupBy<TSource, TKey>(source, keySelector, capacity, comparer);
291 }
292
293 /// <summary>
294 /// Groups the elements of an observable sequence with the specified initial capacity and selects the resulting elements by using a specified function.
295 /// </summary>
296 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
297 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
298 /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
299 /// <param name="source">An observable sequence whose elements to group.</param>
300 /// <param name="keySelector">A function to extract the key for each element.</param>
301 /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
302 /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
303 /// <returns>A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.</returns>
304 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> is null.</exception>
305 /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
306 public static IObservable<IGroupedObservable<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, int capacity)
307 {
308 if (source == null)
309 throw new ArgumentNullException("source");
310 if (keySelector == null)
311 throw new ArgumentNullException("keySelector");
312 if (elementSelector == null)
313 throw new ArgumentNullException("elementSelector");
314 if (capacity < 0)
315 throw new ArgumentOutOfRangeException("capacity");
316
317 return s_impl.GroupBy<TSource, TKey, TElement>(source, keySelector, elementSelector, capacity);
318 }
319
320 /// <summary>
321 /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function and comparer and selects the resulting elements by using a specified function.
322 /// </summary>
323 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
324 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
325 /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
326 /// <param name="source">An observable sequence whose elements to group.</param>
327 /// <param name="keySelector">A function to extract the key for each element.</param>
328 /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
329 /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
330 /// <param name="comparer">An equality comparer to compare keys with.</param>
331 /// <returns>A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.</returns>
332 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> or <paramref name="comparer"/> is null.</exception>
333 /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
334 public static IObservable<IGroupedObservable<TKey, TElement>> GroupBy<TSource, TKey, TElement>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, int capacity, IEqualityComparer<TKey> comparer)
335 {
336 if (source == null)
337 throw new ArgumentNullException("source");
338 if (keySelector == null)
339 throw new ArgumentNullException("keySelector");
340 if (elementSelector == null)
341 throw new ArgumentNullException("elementSelector");
342 if (capacity < 0)
343 throw new ArgumentOutOfRangeException("capacity");
344 if (comparer == null)
345 throw new ArgumentNullException("comparer");
346
347 return s_impl.GroupBy<TSource, TKey, TElement>(source, keySelector, elementSelector, capacity, comparer);
348 }
349
350 #endregion
351
352 #region + GroupByUntil +
353
354 /// <summary>
355 /// Groups the elements of an observable sequence according to a specified key selector function and comparer and selects the resulting elements by using a specified function.
356 /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
357 /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
358 /// </summary>
359 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
360 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
361 /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
362 /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
363 /// <param name="source">An observable sequence whose elements to group.</param>
364 /// <param name="keySelector">A function to extract the key for each element.</param>
365 /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
366 /// <param name="durationSelector">A function to signal the expiration of a group.</param>
367 /// <param name="comparer">An equality comparer to compare keys with.</param>
368 /// <returns>
369 /// A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
370 /// If a group's lifetime expires, a new group with the same key value can be created once an element with such a key value is encountered.
371 /// </returns>
372 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> or <paramref name="durationSelector"/> or <paramref name="comparer"/> is null.</exception>
373 public static IObservable<IGroupedObservable<TKey, TElement>> GroupByUntil<TSource, TKey, TElement, TDuration>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<IGroupedObservable<TKey, TElement>, IObservable<TDuration>> durationSelector, IEqualityComparer<TKey> comparer)
374 {
375 if (source == null)
376 throw new ArgumentNullException("source");
377 if (keySelector == null)
378 throw new ArgumentNullException("keySelector");
379 if (elementSelector == null)
380 throw new ArgumentNullException("elementSelector");
381 if (durationSelector == null)
382 throw new ArgumentNullException("durationSelector");
383 if (comparer == null)
384 throw new ArgumentNullException("comparer");
385
386 return s_impl.GroupByUntil<TSource, TKey, TElement, TDuration>(source, keySelector, elementSelector, durationSelector, comparer);
387 }
388
389 /// <summary>
390 /// Groups the elements of an observable sequence according to a specified key selector function and selects the resulting elements by using a specified function.
391 /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
392 /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
393 /// </summary>
394 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
395 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
396 /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
397 /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
398 /// <param name="source">An observable sequence whose elements to group.</param>
399 /// <param name="keySelector">A function to extract the key for each element.</param>
400 /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
401 /// <param name="durationSelector">A function to signal the expiration of a group.</param>
402 /// <returns>
403 /// A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
404 /// If a group's lifetime expires, a new group with the same key value can be created once an element with such a key value is encoutered.
405 /// </returns>
406 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> or <paramref name="durationSelector"/> is null.</exception>
407 public static IObservable<IGroupedObservable<TKey, TElement>> GroupByUntil<TSource, TKey, TElement, TDuration>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<IGroupedObservable<TKey, TElement>, IObservable<TDuration>> durationSelector)
408 {
409 if (source == null)
410 throw new ArgumentNullException("source");
411 if (keySelector == null)
412 throw new ArgumentNullException("keySelector");
413 if (elementSelector == null)
414 throw new ArgumentNullException("elementSelector");
415 if (durationSelector == null)
416 throw new ArgumentNullException("durationSelector");
417
418 return s_impl.GroupByUntil<TSource, TKey, TElement, TDuration>(source, keySelector, elementSelector, durationSelector);
419 }
420
421 /// <summary>
422 /// Groups the elements of an observable sequence according to a specified key selector function and comparer.
423 /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
424 /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
425 /// </summary>
426 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
427 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
428 /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
429 /// <param name="source">An observable sequence whose elements to group.</param>
430 /// <param name="keySelector">A function to extract the key for each element.</param>
431 /// <param name="durationSelector">A function to signal the expiration of a group.</param>
432 /// <param name="comparer">An equality comparer to compare keys with.</param>
433 /// <returns>
434 /// A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
435 /// If a group's lifetime expires, a new group with the same key value can be created once an element with such a key value is encoutered.
436 /// </returns>
437 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="durationSelector"/> or <paramref name="comparer"/> is null.</exception>
438 public static IObservable<IGroupedObservable<TKey, TSource>> GroupByUntil<TSource, TKey, TDuration>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<IGroupedObservable<TKey, TSource>, IObservable<TDuration>> durationSelector, IEqualityComparer<TKey> comparer)
439 {
440 if (source == null)
441 throw new ArgumentNullException("source");
442 if (keySelector == null)
443 throw new ArgumentNullException("keySelector");
444 if (durationSelector == null)
445 throw new ArgumentNullException("durationSelector");
446 if (comparer == null)
447 throw new ArgumentNullException("comparer");
448
449 return s_impl.GroupByUntil<TSource, TKey, TDuration>(source, keySelector, durationSelector, comparer);
450 }
451
452 /// <summary>
453 /// Groups the elements of an observable sequence according to a specified key selector function.
454 /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
455 /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
456 /// </summary>
457 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
458 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
459 /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
460 /// <param name="source">An observable sequence whose elements to group.</param>
461 /// <param name="keySelector">A function to extract the key for each element.</param>
462 /// <param name="durationSelector">A function to signal the expiration of a group.</param>
463 /// <returns>
464 /// A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
465 /// If a group's lifetime expires, a new group with the same key value can be created once an element with such a key value is encoutered.
466 /// </returns>
467 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="durationSelector"/> is null.</exception>
468 public static IObservable<IGroupedObservable<TKey, TSource>> GroupByUntil<TSource, TKey, TDuration>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<IGroupedObservable<TKey, TSource>, IObservable<TDuration>> durationSelector)
469 {
470 if (source == null)
471 throw new ArgumentNullException("source");
472 if (keySelector == null)
473 throw new ArgumentNullException("keySelector");
474 if (durationSelector == null)
475 throw new ArgumentNullException("durationSelector");
476
477 return s_impl.GroupByUntil<TSource, TKey, TDuration>(source, keySelector, durationSelector);
478 }
479
480 /// <summary>
481 /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function and comparer and selects the resulting elements by using a specified function.
482 /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
483 /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
484 /// </summary>
485 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
486 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
487 /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
488 /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
489 /// <param name="source">An observable sequence whose elements to group.</param>
490 /// <param name="keySelector">A function to extract the key for each element.</param>
491 /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
492 /// <param name="durationSelector">A function to signal the expiration of a group.</param>
493 /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
494 /// <param name="comparer">An equality comparer to compare keys with.</param>
495 /// <returns>
496 /// A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
497 /// If a group's lifetime expires, a new group with the same key value can be created once an element with such a key value is encountered.
498 /// </returns>
499 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> or <paramref name="durationSelector"/> or <paramref name="comparer"/> is null.</exception>
500 /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
501 public static IObservable<IGroupedObservable<TKey, TElement>> GroupByUntil<TSource, TKey, TElement, TDuration>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<IGroupedObservable<TKey, TElement>, IObservable<TDuration>> durationSelector, int capacity, IEqualityComparer<TKey> comparer)
502 {
503 if (source == null)
504 throw new ArgumentNullException("source");
505 if (keySelector == null)
506 throw new ArgumentNullException("keySelector");
507 if (elementSelector == null)
508 throw new ArgumentNullException("elementSelector");
509 if (durationSelector == null)
510 throw new ArgumentNullException("durationSelector");
511 if (capacity < 0)
512 throw new ArgumentOutOfRangeException("capacity");
513 if (comparer == null)
514 throw new ArgumentNullException("comparer");
515
516 return s_impl.GroupByUntil<TSource, TKey, TElement, TDuration>(source, keySelector, elementSelector, durationSelector, capacity, comparer);
517 }
518
519 /// <summary>
520 /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function and selects the resulting elements by using a specified function.
521 /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
522 /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
523 /// </summary>
524 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
525 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
526 /// <typeparam name="TElement">The type of the elements within the groups computed for each element in the source sequence.</typeparam>
527 /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
528 /// <param name="source">An observable sequence whose elements to group.</param>
529 /// <param name="keySelector">A function to extract the key for each element.</param>
530 /// <param name="elementSelector">A function to map each source element to an element in an observable group.</param>
531 /// <param name="durationSelector">A function to signal the expiration of a group.</param>
532 /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
533 /// <returns>
534 /// A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
535 /// If a group's lifetime expires, a new group with the same key value can be created once an element with such a key value is encoutered.
536 /// </returns>
537 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="elementSelector"/> or <paramref name="durationSelector"/> is null.</exception>
538 /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
539 public static IObservable<IGroupedObservable<TKey, TElement>> GroupByUntil<TSource, TKey, TElement, TDuration>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, Func<IGroupedObservable<TKey, TElement>, IObservable<TDuration>> durationSelector, int capacity)
540 {
541 if (source == null)
542 throw new ArgumentNullException("source");
543 if (keySelector == null)
544 throw new ArgumentNullException("keySelector");
545 if (elementSelector == null)
546 throw new ArgumentNullException("elementSelector");
547 if (durationSelector == null)
548 throw new ArgumentNullException("durationSelector");
549 if (capacity < 0)
550 throw new ArgumentOutOfRangeException("capacity");
551
552 return s_impl.GroupByUntil<TSource, TKey, TElement, TDuration>(source, keySelector, elementSelector, durationSelector, capacity);
553 }
554
555 /// <summary>
556 /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function and comparer.
557 /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
558 /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
559 /// </summary>
560 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
561 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
562 /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
563 /// <param name="source">An observable sequence whose elements to group.</param>
564 /// <param name="keySelector">A function to extract the key for each element.</param>
565 /// <param name="durationSelector">A function to signal the expiration of a group.</param>
566 /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
567 /// <param name="comparer">An equality comparer to compare keys with.</param>
568 /// <returns>
569 /// A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
570 /// If a group's lifetime expires, a new group with the same key value can be created once an element with such a key value is encoutered.
571 /// </returns>
572 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="durationSelector"/> or <paramref name="comparer"/> is null.</exception>
573 /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
574 public static IObservable<IGroupedObservable<TKey, TSource>> GroupByUntil<TSource, TKey, TDuration>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<IGroupedObservable<TKey, TSource>, IObservable<TDuration>> durationSelector, int capacity, IEqualityComparer<TKey> comparer)
575 {
576 if (source == null)
577 throw new ArgumentNullException("source");
578 if (keySelector == null)
579 throw new ArgumentNullException("keySelector");
580 if (durationSelector == null)
581 throw new ArgumentNullException("durationSelector");
582 if (capacity < 0)
583 throw new ArgumentOutOfRangeException("capacity");
584 if (comparer == null)
585 throw new ArgumentNullException("comparer");
586
587 return s_impl.GroupByUntil<TSource, TKey, TDuration>(source, keySelector, durationSelector, capacity, comparer);
588 }
589
590 /// <summary>
591 /// Groups the elements of an observable sequence with the specified initial capacity according to a specified key selector function.
592 /// A duration selector function is used to control the lifetime of groups. When a group expires, it receives an OnCompleted notification. When a new element with the same
593 /// key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
594 /// </summary>
595 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
596 /// <typeparam name="TKey">The type of the grouping key computed for each element in the source sequence.</typeparam>
597 /// <typeparam name="TDuration">The type of the elements in the duration sequences obtained for each group to denote its lifetime.</typeparam>
598 /// <param name="source">An observable sequence whose elements to group.</param>
599 /// <param name="keySelector">A function to extract the key for each element.</param>
600 /// <param name="durationSelector">A function to signal the expiration of a group.</param>
601 /// <param name="capacity">The initial number of elements that the underlying dictionary can contain.</param>
602 /// <returns>
603 /// A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
604 /// If a group's lifetime expires, a new group with the same key value can be created once an element with such a key value is encoutered.
605 /// </returns>
606 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="durationSelector"/> is null.</exception>
607 /// <exception cref="ArgumentOutOfRangeException"><paramref name="capacity"/> is less than 0.</exception>
608 public static IObservable<IGroupedObservable<TKey, TSource>> GroupByUntil<TSource, TKey, TDuration>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, Func<IGroupedObservable<TKey, TSource>, IObservable<TDuration>> durationSelector, int capacity)
609 {
610 if (source == null)
611 throw new ArgumentNullException("source");
612 if (keySelector == null)
613 throw new ArgumentNullException("keySelector");
614 if (durationSelector == null)
615 throw new ArgumentNullException("durationSelector");
616 if (capacity < 0)
617 throw new ArgumentOutOfRangeException("capacity");
618
619 return s_impl.GroupByUntil<TSource, TKey, TDuration>(source, keySelector, durationSelector, capacity);
620 }
621
622 #endregion
623
624 #region + GroupJoin +
625
626 /// <summary>
627 /// Correlates the elements of two sequences based on overlapping durations, and groups the results.
628 /// </summary>
629 /// <typeparam name="TLeft">The type of the elements in the left source sequence.</typeparam>
630 /// <typeparam name="TRight">The type of the elements in the right source sequence.</typeparam>
631 /// <typeparam name="TLeftDuration">The type of the elements in the duration sequence denoting the computed duration of each element in the left source sequence.</typeparam>
632 /// <typeparam name="TRightDuration">The type of the elements in the duration sequence denoting the computed duration of each element in the right source sequence.</typeparam>
633 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by invoking the result selector function for source elements with overlapping duration.</typeparam>
634 /// <param name="left">The left observable sequence to join elements for.</param>
635 /// <param name="right">The right observable sequence to join elements for.</param>
636 /// <param name="leftDurationSelector">A function to select the duration of each element of the left observable sequence, used to determine overlap.</param>
637 /// <param name="rightDurationSelector">A function to select the duration of each element of the right observable sequence, used to determine overlap.</param>
638 /// <param name="resultSelector">A function invoked to compute a result element for any element of the left sequence with overlapping elements from the right observable sequence.</param>
639 /// <returns>An observable sequence that contains result elements computed from source elements that have an overlapping duration.</returns>
640 /// <exception cref="ArgumentNullException"><paramref name="left"/> or <paramref name="right"/> or <paramref name="leftDurationSelector"/> or <paramref name="rightDurationSelector"/> or <paramref name="resultSelector"/> is null.</exception>
641 public static IObservable<TResult> GroupJoin<TLeft, TRight, TLeftDuration, TRightDuration, TResult>(this IObservable<TLeft> left, IObservable<TRight> right, Func<TLeft, IObservable<TLeftDuration>> leftDurationSelector, Func<TRight, IObservable<TRightDuration>> rightDurationSelector, Func<TLeft, IObservable<TRight>, TResult> resultSelector)
642 {
643 if (left == null)
644 throw new ArgumentNullException("left");
645 if (right == null)
646 throw new ArgumentNullException("right");
647 if (leftDurationSelector == null)
648 throw new ArgumentNullException("leftDurationSelector");
649 if (rightDurationSelector == null)
650 throw new ArgumentNullException("rightDurationSelector");
651 if (resultSelector == null)
652 throw new ArgumentNullException("resultSelector");
653
654 return s_impl.GroupJoin<TLeft, TRight, TLeftDuration, TRightDuration, TResult>(left, right, leftDurationSelector, rightDurationSelector, resultSelector);
655 }
656
657 #endregion
658
659 #region + Join +
660
661 /// <summary>
662 /// Correlates the elements of two sequences based on overlapping durations.
663 /// </summary>
664 /// <typeparam name="TLeft">The type of the elements in the left source sequence.</typeparam>
665 /// <typeparam name="TRight">The type of the elements in the right source sequence.</typeparam>
666 /// <typeparam name="TLeftDuration">The type of the elements in the duration sequence denoting the computed duration of each element in the left source sequence.</typeparam>
667 /// <typeparam name="TRightDuration">The type of the elements in the duration sequence denoting the computed duration of each element in the right source sequence.</typeparam>
668 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by invoking the result selector function for source elements with overlapping duration.</typeparam>
669 /// <param name="left">The left observable sequence to join elements for.</param>
670 /// <param name="right">The right observable sequence to join elements for.</param>
671 /// <param name="leftDurationSelector">A function to select the duration of each element of the left observable sequence, used to determine overlap.</param>
672 /// <param name="rightDurationSelector">A function to select the duration of each element of the right observable sequence, used to determine overlap.</param>
673 /// <param name="resultSelector">A function invoked to compute a result element for any two overlapping elements of the left and right observable sequences.</param>
674 /// <returns>An observable sequence that contains result elements computed from source elements that have an overlapping duration.</returns>
675 /// <exception cref="ArgumentNullException"><paramref name="left"/> or <paramref name="right"/> or <paramref name="leftDurationSelector"/> or <paramref name="rightDurationSelector"/> or <paramref name="resultSelector"/> is null.</exception>
676 public static IObservable<TResult> Join<TLeft, TRight, TLeftDuration, TRightDuration, TResult>(this IObservable<TLeft> left, IObservable<TRight> right, Func<TLeft, IObservable<TLeftDuration>> leftDurationSelector, Func<TRight, IObservable<TRightDuration>> rightDurationSelector, Func<TLeft, TRight, TResult> resultSelector)
677 {
678 if (left == null)
679 throw new ArgumentNullException("left");
680 if (right == null)
681 throw new ArgumentNullException("right");
682 if (leftDurationSelector == null)
683 throw new ArgumentNullException("leftDurationSelector");
684 if (rightDurationSelector == null)
685 throw new ArgumentNullException("rightDurationSelector");
686 if (resultSelector == null)
687 throw new ArgumentNullException("resultSelector");
688
689 return s_impl.Join<TLeft, TRight, TLeftDuration, TRightDuration, TResult>(left, right, leftDurationSelector, rightDurationSelector, resultSelector);
690 }
691
692 #endregion
693
694 #region + OfType +
695
696 /// <summary>
697 /// Filters the elements of an observable sequence based on the specified type.
698 /// </summary>
699 /// <typeparam name="TResult">The type to filter the elements in the source sequence on.</typeparam>
700 /// <param name="source">The observable sequence that contains the elements to be filtered.</param>
701 /// <returns>An observable sequence that contains elements from the input sequence of type TResult.</returns>
702 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
703 public static IObservable<TResult> OfType<TResult>(this IObservable<object> source)
704 {
705 if (source == null)
706 throw new ArgumentNullException("source");
707
708 return s_impl.OfType<TResult>(source);
709 }
710
711 #endregion
712
713 #region + Select +
714
715 /// <summary>
716 /// Projects each element of an observable sequence into a new form.
717 /// </summary>
718 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
719 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by running the selector function for each element in the source sequence.</typeparam>
720 /// <param name="source">A sequence of elements to invoke a transform function on.</param>
721 /// <param name="selector">A transform function to apply to each source element.</param>
722 /// <returns>An observable sequence whose elements are the result of invoking the transform function on each element of source.</returns>
723 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
724 public static IObservable<TResult> Select<TSource, TResult>(this IObservable<TSource> source, Func<TSource, TResult> selector)
725 {
726 if (source == null)
727 throw new ArgumentNullException("source");
728 if (selector == null)
729 throw new ArgumentNullException("selector");
730
731 return s_impl.Select<TSource, TResult>(source, selector);
732 }
733
734 /// <summary>
735 /// Projects each element of an observable sequence into a new form by incorporating the element's index.
736 /// </summary>
737 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
738 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by running the selector function for each element in the source sequence.</typeparam>
739 /// <param name="source">A sequence of elements to invoke a transform function on.</param>
740 /// <param name="selector">A transform function to apply to each source element; the second parameter of the function represents the index of the source element.</param>
741 /// <returns>An observable sequence whose elements are the result of invoking the transform function on each element of source.</returns>
742 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
743 public static IObservable<TResult> Select<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, TResult> selector)
744 {
745 if (source == null)
746 throw new ArgumentNullException("source");
747 if (selector == null)
748 throw new ArgumentNullException("selector");
749
750 return s_impl.Select<TSource, TResult>(source, selector);
751 }
752
753 #endregion
754
755 #region + SelectMany +
756
757 /// <summary>
758 /// Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
759 /// </summary>
760 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
761 /// <typeparam name="TOther">The type of the elements in the other sequence and the elements in the result sequence.</typeparam>
762 /// <param name="source">An observable sequence of elements to project.</param>
763 /// <param name="other">An observable sequence to project each element from the source sequence onto.</param>
764 /// <returns>An observable sequence whose elements are the result of projecting each source element onto the other sequence and merging all the resulting sequences together.</returns>
765 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="other"/> is null.</exception>
766 public static IObservable<TOther> SelectMany<TSource, TOther>(this IObservable<TSource> source, IObservable<TOther> other)
767 {
768 if (source == null)
769 throw new ArgumentNullException("source");
770 if (other == null)
771 throw new ArgumentNullException("other");
772
773 return s_impl.SelectMany<TSource, TOther>(source, other);
774 }
775
776 /// <summary>
777 /// Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
778 /// </summary>
779 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
780 /// <typeparam name="TResult">The type of the elements in the projected inner sequences and the elements in the merged result sequence.</typeparam>
781 /// <param name="source">An observable sequence of elements to project.</param>
782 /// <param name="selector">A transform function to apply to each element.</param>
783 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.</returns>
784 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
785 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TResult>> selector)
786 {
787 if (source == null)
788 throw new ArgumentNullException("source");
789 if (selector == null)
790 throw new ArgumentNullException("selector");
791
792 return s_impl.SelectMany<TSource, TResult>(source, selector);
793 }
794
795 /// <summary>
796 /// Projects each element of an observable sequence to an observable sequence by incorporating the element's index and merges the resulting observable sequences into one observable sequence.
797 /// </summary>
798 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
799 /// <typeparam name="TResult">The type of the elements in the projected inner sequences and the elements in the merged result sequence.</typeparam>
800 /// <param name="source">An observable sequence of elements to project.</param>
801 /// <param name="selector">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
802 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.</returns>
803 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
804 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TResult>> selector)
805 {
806 if (source == null)
807 throw new ArgumentNullException("source");
808 if (selector == null)
809 throw new ArgumentNullException("selector");
810
811 return s_impl.SelectMany<TSource, TResult>(source, selector);
812 }
813
814 #if !NO_TPL
815 /// <summary>
816 /// Projects each element of an observable sequence to a task and merges all of the task results into one observable sequence.
817 /// </summary>
818 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
819 /// <typeparam name="TResult">The type of the result produced by the projected tasks and the elements in the merged result sequence.</typeparam>
820 /// <param name="source">An observable sequence of elements to project.</param>
821 /// <param name="selector">A transform function to apply to each element.</param>
822 /// <returns>An observable sequence whose elements are the result of the tasks executed for each element of the input sequence.</returns>
823 /// <remarks>This overload supports composition of observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using <see cref="TaskObservableExtensions.ToObservable&lt;TResult&gt;"/>.</remarks>
824 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
825 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, Task<TResult>> selector)
826 {
827 if (source == null)
828 throw new ArgumentNullException("source");
829 if (selector == null)
830 throw new ArgumentNullException("selector");
831
832 return s_impl.SelectMany<TSource, TResult>(source, selector);
833 }
834
835 /// <summary>
836 /// Projects each element of an observable sequence to a task by incorporating the element's index and merges all of the task results into one observable sequence.
837 /// </summary>
838 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
839 /// <typeparam name="TResult">The type of the result produced by the projected tasks and the elements in the merged result sequence.</typeparam>
840 /// <param name="source">An observable sequence of elements to project.</param>
841 /// <param name="selector">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
842 /// <returns>An observable sequence whose elements are the result of the tasks executed for each element of the input sequence.</returns>
843 /// <remarks>This overload supports composition of observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using <see cref="TaskObservableExtensions.ToObservable&lt;TResult&gt;"/>.</remarks>
844 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
845 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, Task<TResult>> selector)
846 {
847 if (source == null)
848 throw new ArgumentNullException("source");
849 if (selector == null)
850 throw new ArgumentNullException("selector");
851
852 return s_impl.SelectMany<TSource, TResult>(source, selector);
853 }
854
855 /// <summary>
856 /// Projects each element of an observable sequence to a task with cancellation support and merges all of the task results into one observable sequence.
857 /// </summary>
858 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
859 /// <typeparam name="TResult">The type of the result produced by the projected tasks and the elements in the merged result sequence.</typeparam>
860 /// <param name="source">An observable sequence of elements to project.</param>
861 /// <param name="selector">A transform function to apply to each element.</param>
862 /// <returns>An observable sequence whose elements are the result of the tasks executed for each element of the input sequence.</returns>
863 /// <remarks>This overload supports composition of observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using <see cref="TaskObservableExtensions.ToObservable&lt;TResult&gt;"/>.</remarks>
864 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
865 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, CancellationToken, Task<TResult>> selector)
866 {
867 if (source == null)
868 throw new ArgumentNullException("source");
869 if (selector == null)
870 throw new ArgumentNullException("selector");
871
872 return s_impl.SelectMany<TSource, TResult>(source, selector);
873 }
874
875 /// <summary>
876 /// Projects each element of an observable sequence to a task by incorporating the element's index with cancellation support and merges all of the task results into one observable sequence.
877 /// </summary>
878 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
879 /// <typeparam name="TResult">The type of the result produced by the projected tasks and the elements in the merged result sequence.</typeparam>
880 /// <param name="source">An observable sequence of elements to project.</param>
881 /// <param name="selector">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
882 /// <returns>An observable sequence whose elements are the result of the tasks executed for each element of the input sequence.</returns>
883 /// <remarks>This overload supports composition of observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using <see cref="TaskObservableExtensions.ToObservable&lt;TResult&gt;"/>.</remarks>
884 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
885 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, CancellationToken, Task<TResult>> selector)
886 {
887 if (source == null)
888 throw new ArgumentNullException("source");
889 if (selector == null)
890 throw new ArgumentNullException("selector");
891
892 return s_impl.SelectMany<TSource, TResult>(source, selector);
893 }
894 #endif
895
896 /// <summary>
897 /// Projects each element of an observable sequence to an observable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
898 /// </summary>
899 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
900 /// <typeparam name="TCollection">The type of the elements in the projected intermediate sequences.</typeparam>
901 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate sequence elements.</typeparam>
902 /// <param name="source">An observable sequence of elements to project.</param>
903 /// <param name="collectionSelector">A transform function to apply to each element.</param>
904 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
905 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.</returns>
906 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="collectionSelector"/> or <paramref name="resultSelector"/> is null.</exception>
907 public static IObservable<TResult> SelectMany<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
908 {
909 if (source == null)
910 throw new ArgumentNullException("source");
911 if (collectionSelector == null)
912 throw new ArgumentNullException("collectionSelector");
913 if (resultSelector == null)
914 throw new ArgumentNullException("resultSelector");
915
916 return s_impl.SelectMany<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
917 }
918
919 /// <summary>
920 /// Projects each element of an observable sequence to an observable sequence by incorporating the element's index, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
921 /// </summary>
922 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
923 /// <typeparam name="TCollection">The type of the elements in the projected intermediate sequences.</typeparam>
924 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate sequence elements.</typeparam>
925 /// <param name="source">An observable sequence of elements to project.</param>
926 /// <param name="collectionSelector">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
927 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence; the second parameter of the function represents the index of the source element and the fourth parameter represents the index of the intermediate element.</param>
928 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.</returns>
929 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="collectionSelector"/> or <paramref name="resultSelector"/> is null.</exception>
930 public static IObservable<TResult> SelectMany<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TCollection>> collectionSelector, Func<TSource, int, TCollection, int, TResult> resultSelector)
931 {
932 if (source == null)
933 throw new ArgumentNullException("source");
934 if (collectionSelector == null)
935 throw new ArgumentNullException("collectionSelector");
936 if (resultSelector == null)
937 throw new ArgumentNullException("resultSelector");
938
939 return s_impl.SelectMany<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
940 }
941
942 #if !NO_TPL
943 /// <summary>
944 /// Projects each element of an observable sequence to a task, invokes the result selector for the source element and the task result, and merges the results into one observable sequence.
945 /// </summary>
946 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
947 /// <typeparam name="TTaskResult">The type of the results produced by the projected intermediate tasks.</typeparam>
948 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate task results.</typeparam>
949 /// <param name="source">An observable sequence of elements to project.</param>
950 /// <param name="taskSelector">A transform function to apply to each element.</param>
951 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
952 /// <returns>An observable sequence whose elements are the result of obtaining a task for each element of the input sequence and then mapping the task's result and its corresponding source element to a result element.</returns>
953 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="taskSelector"/> or <paramref name="resultSelector"/> is null.</exception>
954 /// <remarks>This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using <see cref="TaskObservableExtensions.ToObservable&lt;TResult&gt;"/>.</remarks>
955 public static IObservable<TResult> SelectMany<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, Task<TTaskResult>> taskSelector, Func<TSource, TTaskResult, TResult> resultSelector)
956 {
957 if (source == null)
958 throw new ArgumentNullException("source");
959 if (taskSelector == null)
960 throw new ArgumentNullException("taskSelector");
961 if (resultSelector == null)
962 throw new ArgumentNullException("resultSelector");
963
964 return s_impl.SelectMany<TSource, TTaskResult, TResult>(source, taskSelector, resultSelector);
965 }
966
967 /// <summary>
968 /// Projects each element of an observable sequence to a task by incorporating the element's index, invokes the result selector for the source element and the task result, and merges the results into one observable sequence.
969 /// </summary>
970 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
971 /// <typeparam name="TTaskResult">The type of the results produced by the projected intermediate tasks.</typeparam>
972 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate task results.</typeparam>
973 /// <param name="source">An observable sequence of elements to project.</param>
974 /// <param name="taskSelector">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
975 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence; the second parameter of the function represents the index of the source element.</param>
976 /// <returns>An observable sequence whose elements are the result of obtaining a task for each element of the input sequence and then mapping the task's result and its corresponding source element to a result element.</returns>
977 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="taskSelector"/> or <paramref name="resultSelector"/> is null.</exception>
978 /// <remarks>This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using <see cref="TaskObservableExtensions.ToObservable&lt;TResult&gt;"/>.</remarks>
979 public static IObservable<TResult> SelectMany<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, int, Task<TTaskResult>> taskSelector, Func<TSource, int, TTaskResult, TResult> resultSelector)
980 {
981 if (source == null)
982 throw new ArgumentNullException("source");
983 if (taskSelector == null)
984 throw new ArgumentNullException("taskSelector");
985 if (resultSelector == null)
986 throw new ArgumentNullException("resultSelector");
987
988 return s_impl.SelectMany<TSource, TTaskResult, TResult>(source, taskSelector, resultSelector);
989 }
990
991 /// <summary>
992 /// Projects each element of an observable sequence to a task with cancellation support, invokes the result selector for the source element and the task result, and merges the results into one observable sequence.
993 /// </summary>
994 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
995 /// <typeparam name="TTaskResult">The type of the results produced by the projected intermediate tasks.</typeparam>
996 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate task results.</typeparam>
997 /// <param name="source">An observable sequence of elements to project.</param>
998 /// <param name="taskSelector">A transform function to apply to each element.</param>
999 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
1000 /// <returns>An observable sequence whose elements are the result of obtaining a task for each element of the input sequence and then mapping the task's result and its corresponding source element to a result element.</returns>
1001 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="taskSelector"/> or <paramref name="resultSelector"/> is null.</exception>
1002 /// <remarks>This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using <see cref="TaskObservableExtensions.ToObservable&lt;TResult&gt;"/>.</remarks>
1003 public static IObservable<TResult> SelectMany<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, CancellationToken, Task<TTaskResult>> taskSelector, Func<TSource, TTaskResult, TResult> resultSelector)
1004 {
1005 if (source == null)
1006 throw new ArgumentNullException("source");
1007 if (taskSelector == null)
1008 throw new ArgumentNullException("taskSelector");
1009 if (resultSelector == null)
1010 throw new ArgumentNullException("resultSelector");
1011
1012 return s_impl.SelectMany<TSource, TTaskResult, TResult>(source, taskSelector, resultSelector);
1013 }
1014
1015 /// <summary>
1016 /// Projects each element of an observable sequence to a task by incorporating the element's index with cancellation support, invokes the result selector for the source element and the task result, and merges the results into one observable sequence.
1017 /// </summary>
1018 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1019 /// <typeparam name="TTaskResult">The type of the results produced by the projected intermediate tasks.</typeparam>
1020 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate task results.</typeparam>
1021 /// <param name="source">An observable sequence of elements to project.</param>
1022 /// <param name="taskSelector">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
1023 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence; the second parameter of the function represents the index of the source element.</param>
1024 /// <returns>An observable sequence whose elements are the result of obtaining a task for each element of the input sequence and then mapping the task's result and its corresponding source element to a result element.</returns>
1025 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="taskSelector"/> or <paramref name="resultSelector"/> is null.</exception>
1026 /// <remarks>This overload supports using LINQ query comprehension syntax in C# and Visual Basic to compose observable sequences and tasks, without requiring manual conversion of the tasks to observable sequences using <see cref="TaskObservableExtensions.ToObservable&lt;TResult&gt;"/>.</remarks>
1027 public static IObservable<TResult> SelectMany<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, int, CancellationToken, Task<TTaskResult>> taskSelector, Func<TSource, int, TTaskResult, TResult> resultSelector)
1028 {
1029 if (source == null)
1030 throw new ArgumentNullException("source");
1031 if (taskSelector == null)
1032 throw new ArgumentNullException("taskSelector");
1033 if (resultSelector == null)
1034 throw new ArgumentNullException("resultSelector");
1035
1036 return s_impl.SelectMany<TSource, TTaskResult, TResult>(source, taskSelector, resultSelector);
1037 }
1038 #endif
1039
1040 /// <summary>
1041 /// Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
1042 /// </summary>
1043 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1044 /// <typeparam name="TResult">The type of the elements in the projected inner sequences and the elements in the merged result sequence.</typeparam>
1045 /// <param name="source">An observable sequence of notifications to project.</param>
1046 /// <param name="onNext">A transform function to apply to each element.</param>
1047 /// <param name="onError">A transform function to apply when an error occurs in the source sequence.</param>
1048 /// <param name="onCompleted">A transform function to apply when the end of the source sequence is reached.</param>
1049 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function corresponding to each notification in the input sequence.</returns>
1050 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> or <paramref name="onError"/> or <paramref name="onCompleted"/> is null.</exception>
1051 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TResult>> onNext, Func<Exception, IObservable<TResult>> onError, Func<IObservable<TResult>> onCompleted)
1052 {
1053 if (source == null)
1054 throw new ArgumentNullException("source");
1055 if (onNext == null)
1056 throw new ArgumentNullException("onNext");
1057 if (onError == null)
1058 throw new ArgumentNullException("onError");
1059 if (onCompleted == null)
1060 throw new ArgumentNullException("onCompleted");
1061
1062 return s_impl.SelectMany<TSource, TResult>(source, onNext, onError, onCompleted);
1063 }
1064
1065 /// <summary>
1066 /// Projects each notification of an observable sequence to an observable sequence by incorporating the element's index and merges the resulting observable sequences into one observable sequence.
1067 /// </summary>
1068 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1069 /// <typeparam name="TResult">The type of the elements in the projected inner sequences and the elements in the merged result sequence.</typeparam>
1070 /// <param name="source">An observable sequence of notifications to project.</param>
1071 /// <param name="onNext">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
1072 /// <param name="onError">A transform function to apply when an error occurs in the source sequence.</param>
1073 /// <param name="onCompleted">A transform function to apply when the end of the source sequence is reached.</param>
1074 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function corresponding to each notification in the input sequence.</returns>
1075 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> or <paramref name="onError"/> or <paramref name="onCompleted"/> is null.</exception>
1076 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TResult>> onNext, Func<Exception, IObservable<TResult>> onError, Func<IObservable<TResult>> onCompleted)
1077 {
1078 if (source == null)
1079 throw new ArgumentNullException("source");
1080 if (onNext == null)
1081 throw new ArgumentNullException("onNext");
1082 if (onError == null)
1083 throw new ArgumentNullException("onError");
1084 if (onCompleted == null)
1085 throw new ArgumentNullException("onCompleted");
1086
1087 return s_impl.SelectMany<TSource, TResult>(source, onNext, onError, onCompleted);
1088 }
1089
1090 /// <summary>
1091 /// Projects each element of an observable sequence to an enumerable sequence and concatenates the resulting enumerable sequences into one observable sequence.
1092 /// </summary>
1093 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1094 /// <typeparam name="TResult">The type of the elements in the projected inner enumerable sequences and the elements in the merged result sequence.</typeparam>
1095 /// <param name="source">An observable sequence of elements to project.</param>
1096 /// <param name="selector">A transform function to apply to each element.</param>
1097 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.</returns>
1098 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
1099 /// <remarks>The projected sequences are enumerated synchonously within the OnNext call of the source sequence. In order to do a concurrent, non-blocking merge, change the selector to return an observable sequence obtained using the <see cref="Observable.ToObservable&lt;TSource&gt;(IEnumerable&lt;TSource&gt;)"/> conversion.</remarks>
1100 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IEnumerable<TResult>> selector)
1101 {
1102 if (source == null)
1103 throw new ArgumentNullException("source");
1104 if (selector == null)
1105 throw new ArgumentNullException("selector");
1106
1107 return s_impl.SelectMany<TSource, TResult>(source, selector);
1108 }
1109
1110 /// <summary>
1111 /// Projects each element of an observable sequence to an enumerable sequence by incorporating the element's index and concatenates the resulting enumerable sequences into one observable sequence.
1112 /// </summary>
1113 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1114 /// <typeparam name="TResult">The type of the elements in the projected inner enumerable sequences and the elements in the merged result sequence.</typeparam>
1115 /// <param name="source">An observable sequence of elements to project.</param>
1116 /// <param name="selector">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
1117 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function on each element of the input sequence.</returns>
1118 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
1119 /// <remarks>The projected sequences are enumerated synchonously within the OnNext call of the source sequence. In order to do a concurrent, non-blocking merge, change the selector to return an observable sequence obtained using the <see cref="Observable.ToObservable&lt;TSource&gt;(IEnumerable&lt;TSource&gt;)"/> conversion.</remarks>
1120 public static IObservable<TResult> SelectMany<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IEnumerable<TResult>> selector)
1121 {
1122 if (source == null)
1123 throw new ArgumentNullException("source");
1124 if (selector == null)
1125 throw new ArgumentNullException("selector");
1126
1127 return s_impl.SelectMany<TSource, TResult>(source, selector);
1128 }
1129
1130 /// <summary>
1131 /// Projects each element of an observable sequence to an enumerable sequence, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
1132 /// </summary>
1133 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1134 /// <typeparam name="TCollection">The type of the elements in the projected intermediate enumerable sequences.</typeparam>
1135 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate sequence elements.</typeparam>
1136 /// <param name="source">An observable sequence of elements to project.</param>
1137 /// <param name="collectionSelector">A transform function to apply to each element.</param>
1138 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
1139 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.</returns>
1140 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="collectionSelector"/> or <paramref name="resultSelector"/> is null.</exception>
1141 /// <remarks>The projected sequences are enumerated synchonously within the OnNext call of the source sequence. In order to do a concurrent, non-blocking merge, change the selector to return an observable sequence obtained using the <see cref="Observable.ToObservable&lt;TSource&gt;(IEnumerable&lt;TSource&gt;)"/> conversion.</remarks>
1142 public static IObservable<TResult> SelectMany<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
1143 {
1144 if (source == null)
1145 throw new ArgumentNullException("source");
1146 if (collectionSelector == null)
1147 throw new ArgumentNullException("collectionSelector");
1148 if (resultSelector == null)
1149 throw new ArgumentNullException("resultSelector");
1150
1151 return s_impl.SelectMany<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
1152 }
1153
1154 /// <summary>
1155 /// Projects each element of an observable sequence to an enumerable sequence by incorporating the element's index, invokes the result selector for the source element and each of the corresponding inner sequence's elements, and merges the results into one observable sequence.
1156 /// </summary>
1157 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1158 /// <typeparam name="TCollection">The type of the elements in the projected intermediate enumerable sequences.</typeparam>
1159 /// <typeparam name="TResult">The type of the elements in the result sequence, obtained by using the selector to combine source sequence elements with their corresponding intermediate sequence elements.</typeparam>
1160 /// <param name="source">An observable sequence of elements to project.</param>
1161 /// <param name="collectionSelector">A transform function to apply to each element; the second parameter of the function represents the index of the source element.</param>
1162 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence; the second parameter of the function represents the index of the source element and the fourth parameter represents the index of the intermediate element.</param>
1163 /// <returns>An observable sequence whose elements are the result of invoking the one-to-many transform function collectionSelector on each element of the input sequence and then mapping each of those sequence elements and their corresponding source element to a result element.</returns>
1164 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="collectionSelector"/> or <paramref name="resultSelector"/> is null.</exception>
1165 /// <remarks>The projected sequences are enumerated synchonously within the OnNext call of the source sequence. In order to do a concurrent, non-blocking merge, change the selector to return an observable sequence obtained using the <see cref="Observable.ToObservable&lt;TSource&gt;(IEnumerable&lt;TSource&gt;)"/> conversion.</remarks>
1166 public static IObservable<TResult> SelectMany<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, int, TCollection, int, TResult> resultSelector)
1167 {
1168 if (source == null)
1169 throw new ArgumentNullException("source");
1170 if (collectionSelector == null)
1171 throw new ArgumentNullException("collectionSelector");
1172 if (resultSelector == null)
1173 throw new ArgumentNullException("resultSelector");
1174
1175 return s_impl.SelectMany<TSource, TCollection, TResult>(source, collectionSelector, resultSelector);
1176 }
1177
1178 #endregion
1179
1180 #region + Skip +
1181
1182 /// <summary>
1183 /// Bypasses a specified number of elements in an observable sequence and then returns the remaining elements.
1184 /// </summary>
1185 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1186 /// <param name="source">The sequence to take elements from.</param>
1187 /// <param name="count">The number of elements to skip before returning the remaining elements.</param>
1188 /// <returns>An observable sequence that contains the elements that occur after the specified index in the input sequence.</returns>
1189 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1190 /// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than zero.</exception>
1191 public static IObservable<TSource> Skip<TSource>(this IObservable<TSource> source, int count)
1192 {
1193 if (source == null)
1194 throw new ArgumentNullException("source");
1195 if (count < 0)
1196 throw new ArgumentOutOfRangeException("count");
1197
1198 return s_impl.Skip<TSource>(source, count);
1199 }
1200
1201 #endregion
1202
1203 #region + SkipWhile +
1204
1205 /// <summary>
1206 /// Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
1207 /// </summary>
1208 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1209 /// <param name="source">An observable sequence to return elements from.</param>
1210 /// <param name="predicate">A function to test each element for a condition.</param>
1211 /// <returns>An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.</returns>
1212 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
1213 public static IObservable<TSource> SkipWhile<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
1214 {
1215 if (source == null)
1216 throw new ArgumentNullException("source");
1217 if (predicate == null)
1218 throw new ArgumentNullException("predicate");
1219
1220 return s_impl.SkipWhile<TSource>(source, predicate);
1221 }
1222
1223 /// <summary>
1224 /// Bypasses elements in an observable sequence as long as a specified condition is true and then returns the remaining elements.
1225 /// The element's index is used in the logic of the predicate function.
1226 /// </summary>
1227 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1228 /// <param name="source">An observable sequence to return elements from.</param>
1229 /// <param name="predicate">A function to test each element for a condition; the second parameter of the function represents the index of the source element.</param>
1230 /// <returns>An observable sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.</returns>
1231 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
1232 public static IObservable<TSource> SkipWhile<TSource>(this IObservable<TSource> source, Func<TSource, int, bool> predicate)
1233 {
1234 if (source == null)
1235 throw new ArgumentNullException("source");
1236 if (predicate == null)
1237 throw new ArgumentNullException("predicate");
1238
1239 return s_impl.SkipWhile<TSource>(source, predicate);
1240 }
1241
1242 #endregion
1243
1244 #region + Take +
1245
1246 /// <summary>
1247 /// Returns a specified number of contiguous elements from the start of an observable sequence.
1248 /// </summary>
1249 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1250 /// <param name="source">The sequence to take elements from.</param>
1251 /// <param name="count">The number of elements to return.</param>
1252 /// <returns>An observable sequence that contains the specified number of elements from the start of the input sequence.</returns>
1253 /// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
1254 /// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than zero.</exception>
1255 public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, int count)
1256 {
1257 if (source == null)
1258 throw new ArgumentNullException("source");
1259 if (count < 0)
1260 throw new ArgumentOutOfRangeException("count");
1261
1262 return s_impl.Take<TSource>(source, count);
1263 }
1264
1265 /// <summary>
1266 /// Returns a specified number of contiguous elements from the start of an observable sequence, using the specified scheduler for the edge case of Take(0).
1267 /// </summary>
1268 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1269 /// <param name="source">The sequence to take elements from.</param>
1270 /// <param name="count">The number of elements to return.</param>
1271 /// <param name="scheduler">Scheduler used to produce an OnCompleted message in case <paramref name="count">count</paramref> is set to 0.</param>
1272 /// <returns>An observable sequence that contains the specified number of elements from the start of the input sequence.</returns>
1273 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception>
1274 /// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than zero.</exception>
1275 public static IObservable<TSource> Take<TSource>(this IObservable<TSource> source, int count, IScheduler scheduler)
1276 {
1277 if (source == null)
1278 throw new ArgumentNullException("source");
1279 if (count < 0)
1280 throw new ArgumentOutOfRangeException("count");
1281 if (scheduler == null)
1282 throw new ArgumentNullException("scheduler");
1283
1284 return s_impl.Take<TSource>(source, count, scheduler);
1285 }
1286
1287 #endregion
1288
1289 #region + TakeWhile +
1290
1291 /// <summary>
1292 /// Returns elements from an observable sequence as long as a specified condition is true.
1293 /// </summary>
1294 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1295 /// <param name="source">A sequence to return elements from.</param>
1296 /// <param name="predicate">A function to test each element for a condition.</param>
1297 /// <returns>An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.</returns>
1298 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
1299 public static IObservable<TSource> TakeWhile<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
1300 {
1301 if (source == null)
1302 throw new ArgumentNullException("source");
1303 if (predicate == null)
1304 throw new ArgumentNullException("predicate");
1305
1306 return s_impl.TakeWhile<TSource>(source, predicate);
1307 }
1308
1309 /// <summary>
1310 /// Returns elements from an observable sequence as long as a specified condition is true.
1311 /// The element's index is used in the logic of the predicate function.
1312 /// </summary>
1313 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1314 /// <param name="source">A sequence to return elements from.</param>
1315 /// <param name="predicate">A function to test each element for a condition; the second parameter of the function represents the index of the source element.</param>
1316 /// <returns>An observable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.</returns>
1317 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
1318 public static IObservable<TSource> TakeWhile<TSource>(this IObservable<TSource> source, Func<TSource, int, bool> predicate)
1319 {
1320 if (source == null)
1321 throw new ArgumentNullException("source");
1322 if (predicate == null)
1323 throw new ArgumentNullException("predicate");
1324
1325 return s_impl.TakeWhile<TSource>(source, predicate);
1326 }
1327
1328 #endregion
1329
1330 #region + Where +
1331
1332 /// <summary>
1333 /// Filters the elements of an observable sequence based on a predicate.
1334 /// </summary>
1335 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1336 /// <param name="source">An observable sequence whose elements to filter.</param>
1337 /// <param name="predicate">A function to test each source element for a condition.</param>
1338 /// <returns>An observable sequence that contains elements from the input sequence that satisfy the condition.</returns>
1339 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
1340 public static IObservable<TSource> Where<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
1341 {
1342 if (source == null)
1343 throw new ArgumentNullException("source");
1344 if (predicate == null)
1345 throw new ArgumentNullException("predicate");
1346
1347 return s_impl.Where<TSource>(source, predicate);
1348 }
1349
1350 /// <summary>
1351 /// Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
1352 /// </summary>
1353 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
1354 /// <param name="source">An observable sequence whose elements to filter.</param>
1355 /// <param name="predicate">A function to test each source element for a conditio; the second parameter of the function represents the index of the source element.</param>
1356 /// <returns>An observable sequence that contains elements from the input sequence that satisfy the condition.</returns>
1357 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
1358 public static IObservable<TSource> Where<TSource>(this IObservable<TSource> source, Func<TSource, int, bool> predicate)
1359 {
1360 if (source == null)
1361 throw new ArgumentNullException("source");
1362 if (predicate == null)
1363 throw new ArgumentNullException("predicate");
1364
1365 return s_impl.Where<TSource>(source, predicate);
1366 }
1367
1368 #endregion
1369 }
1370 }