Debian Codegraph @

external/rx/Rx/NET/Source/System.Reactive.Observable.Aliases/Observable.Aliases.cs

raw
1 // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
2
3 #pragma warning disable 1591
4
5 using System.Collections.Generic;
6 using System.Reactive.Concurrency;
7 using System.Reactive.Linq;
8 using System.Reactive;
9
10 #if !NO_TPL
11 using System.Reactive.Threading.Tasks; // needed for doc comments
12 using System.Threading;
13 using System.Threading.Tasks;
14 #endif
15
16 /*
17 * Note: these methods just call methods in Observable.StandardSequenceOperators.cs
18 * in order to create the following method aliases:
19 *
20 * Map = Select
21 * FlatMap = SelectMany
22 * Filter = Where
23 *
24 */
25
26 namespace System.Reactive.Observable.Aliases
27 {
28 public static class QueryLanguage
29 {
30 #region + Map +
31
32 /// <summary>
33 /// Projects each element of an observable sequence into a new form. Synonym for the method 'Select'
34 /// </summary>
35 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
36 /// <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>
37 /// <param name="source">A sequence of elements to invoke a transform function on.</param>
38 /// <param name="selector">A transform function to apply to each source element.</param>
39 /// <returns>An observable sequence whose elements are the result of invoking the transform function on each element of source.</returns>
40 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
41 public static IObservable<TResult> Map<TSource, TResult>(this IObservable<TSource> source, Func<TSource, TResult> selector)
42 {
43 return source.Select<TSource, TResult>(selector);
44 }
45
46 /// <summary>
47 /// Projects each element of an observable sequence into a new form by incorporating the element's index. Synonym for the method 'Select'
48 /// </summary>
49 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
50 /// <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>
51 /// <param name="source">A sequence of elements to invoke a transform function on.</param>
52 /// <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>
53 /// <returns>An observable sequence whose elements are the result of invoking the transform function on each element of source.</returns>
54 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
55 public static IObservable<TResult> Map<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, TResult> selector)
56 {
57 return source.Select<TSource, TResult>(selector);
58 }
59
60 #endregion
61
62 #region + FlatMap +
63
64 /// <summary>
65 /// Projects each element of the source observable sequence to the other observable sequence and merges the resulting observable sequences into one observable sequence.
66 /// Synonym for the method 'SelectMany'
67 /// </summary>
68 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
69 /// <typeparam name="TOther">The type of the elements in the other sequence and the elements in the result sequence.</typeparam>
70 /// <param name="source">An observable sequence of elements to project.</param>
71 /// <param name="other">An observable sequence to project each element from the source sequence onto.</param>
72 /// <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>
73 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="other"/> is null.</exception>
74 public static IObservable<TOther> FlatMap<TSource, TOther>(this IObservable<TSource> source, IObservable<TOther> other)
75 {
76 return source.SelectMany<TSource, TOther>(other);
77 }
78
79 /// <summary>
80 /// Projects each element of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
81 /// Synonym for the method 'SelectMany'
82 /// </summary>
83 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
84 /// <typeparam name="TResult">The type of the elements in the projected inner sequences and the elements in the merged result sequence.</typeparam>
85 /// <param name="source">An observable sequence of elements to project.</param>
86 /// <param name="selector">A transform function to apply to each element.</param>
87 /// <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>
88 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
89 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TResult>> selector)
90 {
91 return source.SelectMany<TSource, TResult>(selector);
92 }
93
94 /// <summary>
95 /// 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.
96 /// Synonym for the method 'SelectMany'
97 /// </summary>
98 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
99 /// <typeparam name="TResult">The type of the elements in the projected inner sequences and the elements in the merged result sequence.</typeparam>
100 /// <param name="source">An observable sequence of elements to project.</param>
101 /// <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>
102 /// <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>
103 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
104 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TResult>> selector)
105 {
106 return source.SelectMany<TSource, TResult>(selector);
107 }
108
109 #if !NO_TPL
110 /// <summary>
111 /// Projects each element of an observable sequence to a task and merges all of the task results into one observable sequence.
112 /// Synonym for the method 'SelectMany'
113 /// </summary>
114 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
115 /// <typeparam name="TResult">The type of the result produced by the projected tasks and the elements in the merged result sequence.</typeparam>
116 /// <param name="source">An observable sequence of elements to project.</param>
117 /// <param name="selector">A transform function to apply to each element.</param>
118 /// <returns>An observable sequence whose elements are the result of the tasks executed for each element of the input sequence.</returns>
119 /// <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>
120 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
121 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, Task<TResult>> selector)
122 {
123 return source.SelectMany<TSource, TResult>(selector);
124 }
125
126 /// <summary>
127 /// 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.
128 /// Synonym for the method 'SelectMany'
129 /// </summary>
130 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
131 /// <typeparam name="TResult">The type of the result produced by the projected tasks and the elements in the merged result sequence.</typeparam>
132 /// <param name="source">An observable sequence of elements to project.</param>
133 /// <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>
134 /// <returns>An observable sequence whose elements are the result of the tasks executed for each element of the input sequence.</returns>
135 /// <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>
136 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
137 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, Task<TResult>> selector)
138 {
139 return source.SelectMany<TSource, TResult>(selector);
140 }
141
142 /// <summary>
143 /// Projects each element of an observable sequence to a task with cancellation support and merges all of the task results into one observable sequence.
144 /// Synonym for the method 'SelectMany'
145 /// </summary>
146 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
147 /// <typeparam name="TResult">The type of the result produced by the projected tasks and the elements in the merged result sequence.</typeparam>
148 /// <param name="source">An observable sequence of elements to project.</param>
149 /// <param name="selector">A transform function to apply to each element.</param>
150 /// <returns>An observable sequence whose elements are the result of the tasks executed for each element of the input sequence.</returns>
151 /// <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>
152 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
153 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, CancellationToken, Task<TResult>> selector)
154 {
155 return source.SelectMany<TSource, TResult>(selector);
156 }
157
158 /// <summary>
159 /// 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.
160 /// Synonym for the method 'SelectMany'
161 /// </summary>
162 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
163 /// <typeparam name="TResult">The type of the result produced by the projected tasks and the elements in the merged result sequence.</typeparam>
164 /// <param name="source">An observable sequence of elements to project.</param>
165 /// <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>
166 /// <returns>An observable sequence whose elements are the result of the tasks executed for each element of the input sequence.</returns>
167 /// <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>
168 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
169 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, CancellationToken, Task<TResult>> selector)
170 {
171 return source.SelectMany<TSource, TResult>(selector);
172 }
173 #endif
174
175 /// <summary>
176 /// 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.
177 /// Synonym for the method 'SelectMany'
178 /// </summary>
179 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
180 /// <typeparam name="TCollection">The type of the elements in the projected intermediate sequences.</typeparam>
181 /// <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>
182 /// <param name="source">An observable sequence of elements to project.</param>
183 /// <param name="collectionSelector">A transform function to apply to each element.</param>
184 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
185 /// <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>
186 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="collectionSelector"/> or <paramref name="resultSelector"/> is null.</exception>
187 public static IObservable<TResult> FlatMap<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
188 {
189 return source.SelectMany<TSource, TCollection, TResult>(collectionSelector, resultSelector);
190 }
191
192 /// <summary>
193 /// 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.
194 /// Synonym for the method 'SelectMany'
195 /// </summary>
196 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
197 /// <typeparam name="TCollection">The type of the elements in the projected intermediate sequences.</typeparam>
198 /// <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>
199 /// <param name="source">An observable sequence of elements to project.</param>
200 /// <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>
201 /// <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>
202 /// <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>
203 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="collectionSelector"/> or <paramref name="resultSelector"/> is null.</exception>
204 public static IObservable<TResult> FlatMap<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TCollection>> collectionSelector, Func<TSource, int, TCollection, int, TResult> resultSelector)
205 {
206 return source.SelectMany<TSource, TCollection, TResult>(collectionSelector, resultSelector);
207 }
208
209 #if !NO_TPL
210 /// <summary>
211 /// 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.
212 /// Synonym for the method 'SelectMany'
213 /// </summary>
214 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
215 /// <typeparam name="TTaskResult">The type of the results produced by the projected intermediate tasks.</typeparam>
216 /// <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>
217 /// <param name="source">An observable sequence of elements to project.</param>
218 /// <param name="taskSelector">A transform function to apply to each element.</param>
219 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
220 /// <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>
221 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="taskSelector"/> or <paramref name="resultSelector"/> is null.</exception>
222 /// <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>
223 public static IObservable<TResult> FlatMap<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, Task<TTaskResult>> taskSelector, Func<TSource, TTaskResult, TResult> resultSelector)
224 {
225 return source.SelectMany<TSource, TTaskResult, TResult>(taskSelector, resultSelector);
226 }
227
228 /// <summary>
229 /// 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.
230 /// Synonym for the method 'SelectMany'
231 /// </summary>
232 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
233 /// <typeparam name="TTaskResult">The type of the results produced by the projected intermediate tasks.</typeparam>
234 /// <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>
235 /// <param name="source">An observable sequence of elements to project.</param>
236 /// <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>
237 /// <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>
238 /// <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>
239 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="taskSelector"/> or <paramref name="resultSelector"/> is null.</exception>
240 /// <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>
241 public static IObservable<TResult> FlatMap<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, int, Task<TTaskResult>> taskSelector, Func<TSource, int, TTaskResult, TResult> resultSelector)
242 {
243 return source.SelectMany<TSource, TTaskResult, TResult>(taskSelector, resultSelector);
244 }
245
246 /// <summary>
247 /// 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.
248 /// Synonym for the method 'SelectMany'
249 /// </summary>
250 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
251 /// <typeparam name="TTaskResult">The type of the results produced by the projected intermediate tasks.</typeparam>
252 /// <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>
253 /// <param name="source">An observable sequence of elements to project.</param>
254 /// <param name="taskSelector">A transform function to apply to each element.</param>
255 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
256 /// <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>
257 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="taskSelector"/> or <paramref name="resultSelector"/> is null.</exception>
258 /// <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>
259 public static IObservable<TResult> FlatMap<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, CancellationToken, Task<TTaskResult>> taskSelector, Func<TSource, TTaskResult, TResult> resultSelector)
260 {
261 return source.SelectMany<TSource, TTaskResult, TResult>(taskSelector, resultSelector);
262 }
263
264 /// <summary>
265 /// 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.
266 /// Synonym for the method 'SelectMany'
267 /// </summary>
268 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
269 /// <typeparam name="TTaskResult">The type of the results produced by the projected intermediate tasks.</typeparam>
270 /// <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>
271 /// <param name="source">An observable sequence of elements to project.</param>
272 /// <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>
273 /// <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>
274 /// <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>
275 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="taskSelector"/> or <paramref name="resultSelector"/> is null.</exception>
276 /// <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>
277 public static IObservable<TResult> FlatMap<TSource, TTaskResult, TResult>(this IObservable<TSource> source, Func<TSource, int, CancellationToken, Task<TTaskResult>> taskSelector, Func<TSource, int, TTaskResult, TResult> resultSelector)
278 {
279 return source.SelectMany<TSource, TTaskResult, TResult>(taskSelector, resultSelector);
280 }
281 #endif
282
283 /// <summary>
284 /// Projects each notification of an observable sequence to an observable sequence and merges the resulting observable sequences into one observable sequence.
285 /// Synonym for the method 'SelectMany'
286 /// </summary>
287 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
288 /// <typeparam name="TResult">The type of the elements in the projected inner sequences and the elements in the merged result sequence.</typeparam>
289 /// <param name="source">An observable sequence of notifications to project.</param>
290 /// <param name="onNext">A transform function to apply to each element.</param>
291 /// <param name="onError">A transform function to apply when an error occurs in the source sequence.</param>
292 /// <param name="onCompleted">A transform function to apply when the end of the source sequence is reached.</param>
293 /// <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>
294 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> or <paramref name="onError"/> or <paramref name="onCompleted"/> is null.</exception>
295 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IObservable<TResult>> onNext, Func<Exception, IObservable<TResult>> onError, Func<IObservable<TResult>> onCompleted)
296 {
297 return source.SelectMany<TSource, TResult>(onNext, onError, onCompleted);
298 }
299
300 /// <summary>
301 /// 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.
302 /// Synonym for the method 'SelectMany'
303 /// </summary>
304 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
305 /// <typeparam name="TResult">The type of the elements in the projected inner sequences and the elements in the merged result sequence.</typeparam>
306 /// <param name="source">An observable sequence of notifications to project.</param>
307 /// <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>
308 /// <param name="onError">A transform function to apply when an error occurs in the source sequence.</param>
309 /// <param name="onCompleted">A transform function to apply when the end of the source sequence is reached.</param>
310 /// <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>
311 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> or <paramref name="onError"/> or <paramref name="onCompleted"/> is null.</exception>
312 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IObservable<TResult>> onNext, Func<Exception, IObservable<TResult>> onError, Func<IObservable<TResult>> onCompleted)
313 {
314 return source.SelectMany<TSource, TResult>(onNext, onError, onCompleted);
315 }
316
317 /// <summary>
318 /// Projects each element of an observable sequence to an enumerable sequence and concatenates the resulting enumerable sequences into one observable sequence.
319 /// Synonym for the method 'SelectMany'
320 /// </summary>
321 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
322 /// <typeparam name="TResult">The type of the elements in the projected inner enumerable sequences and the elements in the merged result sequence.</typeparam>
323 /// <param name="source">An observable sequence of elements to project.</param>
324 /// <param name="selector">A transform function to apply to each element.</param>
325 /// <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>
326 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
327 /// <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="Linq.Observable.ToObservable&lt;TSource&gt;(IEnumerable&lt;TSource&gt;)"/> conversion.</remarks>
328 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, IEnumerable<TResult>> selector)
329 {
330 return source.SelectMany<TSource, TResult>(selector);
331 }
332
333 /// <summary>
334 /// 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.
335 /// Synonym for the method 'SelectMany'
336 /// </summary>
337 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
338 /// <typeparam name="TResult">The type of the elements in the projected inner enumerable sequences and the elements in the merged result sequence.</typeparam>
339 /// <param name="source">An observable sequence of elements to project.</param>
340 /// <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>
341 /// <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>
342 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
343 /// <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="Linq.Observable.ToObservable&lt;TSource&gt;(IEnumerable&lt;TSource&gt;)"/> conversion.</remarks>
344 public static IObservable<TResult> FlatMap<TSource, TResult>(this IObservable<TSource> source, Func<TSource, int, IEnumerable<TResult>> selector)
345 {
346 return source.SelectMany<TSource, TResult>(selector);
347 }
348
349 /// <summary>
350 /// 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.
351 /// Synonym for the method 'SelectMany'
352 /// </summary>
353 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
354 /// <typeparam name="TCollection">The type of the elements in the projected intermediate enumerable sequences.</typeparam>
355 /// <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>
356 /// <param name="source">An observable sequence of elements to project.</param>
357 /// <param name="collectionSelector">A transform function to apply to each element.</param>
358 /// <param name="resultSelector">A transform function to apply to each element of the intermediate sequence.</param>
359 /// <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>
360 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="collectionSelector"/> or <paramref name="resultSelector"/> is null.</exception>
361 /// <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="Linq.Observable.ToObservable&lt;TSource&gt;(IEnumerable&lt;TSource&gt;)"/> conversion.</remarks>
362 public static IObservable<TResult> FlatMap<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, IEnumerable<TCollection>> collectionSelector, Func<TSource, TCollection, TResult> resultSelector)
363 {
364 return source.SelectMany<TSource, TCollection, TResult>(collectionSelector, resultSelector);
365 }
366
367 /// <summary>
368 /// 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.
369 /// Synonym for the method 'SelectMany'
370 /// </summary>
371 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
372 /// <typeparam name="TCollection">The type of the elements in the projected intermediate enumerable sequences.</typeparam>
373 /// <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>
374 /// <param name="source">An observable sequence of elements to project.</param>
375 /// <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>
376 /// <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>
377 /// <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>
378 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="collectionSelector"/> or <paramref name="resultSelector"/> is null.</exception>
379 /// <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="Linq.Observable.ToObservable&lt;TSource&gt;(IEnumerable&lt;TSource&gt;)"/> conversion.</remarks>
380 public static IObservable<TResult> FlatMap<TSource, TCollection, TResult>(this IObservable<TSource> source, Func<TSource, int, IEnumerable<TCollection>> collectionSelector, Func<TSource, int, TCollection, int, TResult> resultSelector)
381 {
382 return source.SelectMany<TSource, TCollection, TResult>(collectionSelector, resultSelector);
383 }
384
385 #endregion
386
387 #region + Filter +
388
389 /// <summary>
390 /// Filters the elements of an observable sequence based on a predicate.
391 /// Synonym for the method 'Where'
392 /// </summary>
393 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
394 /// <param name="source">An observable sequence whose elements to filter.</param>
395 /// <param name="predicate">A function to test each source element for a condition.</param>
396 /// <returns>An observable sequence that contains elements from the input sequence that satisfy the condition.</returns>
397 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
398 public static IObservable<TSource> Filter<TSource>(this IObservable<TSource> source, Func<TSource, bool> predicate)
399 {
400 return source.Where<TSource>(predicate);
401 }
402
403 /// <summary>
404 /// Filters the elements of an observable sequence based on a predicate by incorporating the element's index.
405 /// Synonym for the method 'Where'
406 /// </summary>
407 /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
408 /// <param name="source">An observable sequence whose elements to filter.</param>
409 /// <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>
410 /// <returns>An observable sequence that contains elements from the input sequence that satisfy the condition.</returns>
411 /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="predicate"/> is null.</exception>
412 public static IObservable<TSource> Filter<TSource>(this IObservable<TSource> source, Func<TSource, int, bool> predicate)
413 {
414 return source.Where<TSource>(predicate);
415 }
416
417 #endregion
418 }
419
420 }
421
422 #pragma warning restore 1591