| 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 |
namespace System.Reactive.Linq |
| 7 |
{ |
| 8 |
public static partial class Observable |
| 9 |
{ |
| 10 |
#region + AsObservable + |
| 11 |
|
| 12 |
/// <summary> |
| 13 |
/// Hides the identity of an observable sequence. |
| 14 |
/// </summary> |
| 15 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 16 |
/// <param name="source">An observable sequence whose identity to hide.</param> |
| 17 |
/// <returns>An observable sequence that hides the identity of the source sequence.</returns> |
| 18 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 19 |
public static IObservable<TSource> AsObservable<TSource>(this IObservable<TSource> source) |
| 20 |
{ |
| 21 |
if (source == null) |
| 22 |
throw new ArgumentNullException("source"); |
| 23 |
|
| 24 |
return s_impl.AsObservable<TSource>(source); |
| 25 |
} |
| 26 |
|
| 27 |
#endregion |
| 28 |
|
| 29 |
#region + Buffer + |
| 30 |
|
| 31 |
/// <summary> |
| 32 |
/// Projects each element of an observable sequence into consecutive non-overlapping buffers which are produced based on element count information. |
| 33 |
/// </summary> |
| 34 |
/// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam> |
| 35 |
/// <param name="source">Source sequence to produce buffers over.</param> |
| 36 |
/// <param name="count">Length of each buffer.</param> |
| 37 |
/// <returns>An observable sequence of buffers.</returns> |
| 38 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 39 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than or equal to zero.</exception> |
| 40 |
public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, int count) |
| 41 |
{ |
| 42 |
if (source == null) |
| 43 |
throw new ArgumentNullException("source"); |
| 44 |
if (count <= 0) |
| 45 |
throw new ArgumentOutOfRangeException("count"); |
| 46 |
|
| 47 |
return s_impl.Buffer<TSource>(source, count); |
| 48 |
} |
| 49 |
|
| 50 |
/// <summary> |
| 51 |
/// Projects each element of an observable sequence into zero or more buffers which are produced based on element count information. |
| 52 |
/// </summary> |
| 53 |
/// <typeparam name="TSource">The type of the elements in the source sequence, and in the lists in the result sequence.</typeparam> |
| 54 |
/// <param name="source">Source sequence to produce buffers over.</param> |
| 55 |
/// <param name="count">Length of each buffer.</param> |
| 56 |
/// <param name="skip">Number of elements to skip between creation of consecutive buffers.</param> |
| 57 |
/// <returns>An observable sequence of buffers.</returns> |
| 58 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 59 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> or <paramref name="skip"/> is less than or equal to zero.</exception> |
| 60 |
public static IObservable<IList<TSource>> Buffer<TSource>(this IObservable<TSource> source, int count, int skip) |
| 61 |
{ |
| 62 |
if (source == null) |
| 63 |
throw new ArgumentNullException("source"); |
| 64 |
if (count <= 0) |
| 65 |
throw new ArgumentOutOfRangeException("count"); |
| 66 |
if (skip <= 0) |
| 67 |
throw new ArgumentOutOfRangeException("skip"); |
| 68 |
|
| 69 |
return s_impl.Buffer<TSource>(source, count, skip); |
| 70 |
} |
| 71 |
|
| 72 |
#endregion |
| 73 |
|
| 74 |
#region + Dematerialize + |
| 75 |
|
| 76 |
/// <summary> |
| 77 |
/// Dematerializes the explicit notification values of an observable sequence as implicit notifications. |
| 78 |
/// </summary> |
| 79 |
/// <typeparam name="TSource">The type of the elements materialized in the source sequence notification objects.</typeparam> |
| 80 |
/// <param name="source">An observable sequence containing explicit notification values which have to be turned into implicit notifications.</param> |
| 81 |
/// <returns>An observable sequence exhibiting the behavior corresponding to the source sequence's notification values.</returns> |
| 82 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 83 |
public static IObservable<TSource> Dematerialize<TSource>(this IObservable<Notification<TSource>> source) |
| 84 |
{ |
| 85 |
if (source == null) |
| 86 |
throw new ArgumentNullException("source"); |
| 87 |
|
| 88 |
return s_impl.Dematerialize<TSource>(source); |
| 89 |
} |
| 90 |
|
| 91 |
#endregion |
| 92 |
|
| 93 |
#region + DistinctUntilChanged + |
| 94 |
|
| 95 |
/// <summary> |
| 96 |
/// Returns an observable sequence that contains only distinct contiguous elements. |
| 97 |
/// </summary> |
| 98 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 99 |
/// <param name="source">An observable sequence to retain distinct contiguous elements for.</param> |
| 100 |
/// <returns>An observable sequence only containing the distinct contiguous elements from the source sequence.</returns> |
| 101 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 102 |
public static IObservable<TSource> DistinctUntilChanged<TSource>(this IObservable<TSource> source) |
| 103 |
{ |
| 104 |
if (source == null) |
| 105 |
throw new ArgumentNullException("source"); |
| 106 |
|
| 107 |
return s_impl.DistinctUntilChanged<TSource>(source); |
| 108 |
} |
| 109 |
|
| 110 |
/// <summary> |
| 111 |
/// Returns an observable sequence that contains only distinct contiguous elements according to the comparer. |
| 112 |
/// </summary> |
| 113 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 114 |
/// <param name="source">An observable sequence to retain distinct contiguous elements for.</param> |
| 115 |
/// <param name="comparer">Equality comparer for source elements.</param> |
| 116 |
/// <returns>An observable sequence only containing the distinct contiguous elements from the source sequence.</returns> |
| 117 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="comparer"/> is null.</exception> |
| 118 |
public static IObservable<TSource> DistinctUntilChanged<TSource>(this IObservable<TSource> source, IEqualityComparer<TSource> comparer) |
| 119 |
{ |
| 120 |
if (source == null) |
| 121 |
throw new ArgumentNullException("source"); |
| 122 |
if (comparer == null) |
| 123 |
throw new ArgumentNullException("comparer"); |
| 124 |
|
| 125 |
return s_impl.DistinctUntilChanged<TSource>(source, comparer); |
| 126 |
} |
| 127 |
|
| 128 |
/// <summary> |
| 129 |
/// Returns an observable sequence that contains only distinct contiguous elements according to the keySelector. |
| 130 |
/// </summary> |
| 131 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 132 |
/// <typeparam name="TKey">The type of the discriminator key computed for each element in the source sequence.</typeparam> |
| 133 |
/// <param name="source">An observable sequence to retain distinct contiguous elements for, based on a computed key value.</param> |
| 134 |
/// <param name="keySelector">A function to compute the comparison key for each element.</param> |
| 135 |
/// <returns>An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.</returns> |
| 136 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> is null.</exception> |
| 137 |
public static IObservable<TSource> DistinctUntilChanged<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector) |
| 138 |
{ |
| 139 |
if (source == null) |
| 140 |
throw new ArgumentNullException("source"); |
| 141 |
if (keySelector == null) |
| 142 |
throw new ArgumentNullException("keySelector"); |
| 143 |
|
| 144 |
return s_impl.DistinctUntilChanged<TSource, TKey>(source, keySelector); |
| 145 |
} |
| 146 |
|
| 147 |
/// <summary> |
| 148 |
/// Returns an observable sequence that contains only distinct contiguous elements according to the keySelector and the comparer. |
| 149 |
/// </summary> |
| 150 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 151 |
/// <typeparam name="TKey">The type of the discriminator key computed for each element in the source sequence.</typeparam> |
| 152 |
/// <param name="source">An observable sequence to retain distinct contiguous elements for, based on a computed key value.</param> |
| 153 |
/// <param name="keySelector">A function to compute the comparison key for each element.</param> |
| 154 |
/// <param name="comparer">Equality comparer for computed key values.</param> |
| 155 |
/// <returns>An observable sequence only containing the distinct contiguous elements, based on a computed key value, from the source sequence.</returns> |
| 156 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="keySelector"/> or <paramref name="comparer"/> is null.</exception> |
| 157 |
public static IObservable<TSource> DistinctUntilChanged<TSource, TKey>(this IObservable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer) |
| 158 |
{ |
| 159 |
if (source == null) |
| 160 |
throw new ArgumentNullException("source"); |
| 161 |
if (keySelector == null) |
| 162 |
throw new ArgumentNullException("keySelector"); |
| 163 |
if (comparer == null) |
| 164 |
throw new ArgumentNullException("comparer"); |
| 165 |
|
| 166 |
return s_impl.DistinctUntilChanged<TSource, TKey>(source, keySelector, comparer); |
| 167 |
} |
| 168 |
|
| 169 |
#endregion |
| 170 |
|
| 171 |
#region + Do + |
| 172 |
|
| 173 |
/// <summary> |
| 174 |
/// Invokes an action for each element in the observable sequence, and propagates all observer messages through the result sequence. |
| 175 |
/// This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline. |
| 176 |
/// </summary> |
| 177 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 178 |
/// <param name="source">Source sequence.</param> |
| 179 |
/// <param name="onNext">Action to invoke for each element in the observable sequence.</param> |
| 180 |
/// <returns>The source sequence with the side-effecting behavior applied.</returns> |
| 181 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> is null.</exception> |
| 182 |
public static IObservable<TSource> Do<TSource>(this IObservable<TSource> source, Action<TSource> onNext) |
| 183 |
{ |
| 184 |
if (source == null) |
| 185 |
throw new ArgumentNullException("source"); |
| 186 |
if (onNext == null) |
| 187 |
throw new ArgumentNullException("onNext"); |
| 188 |
|
| 189 |
return s_impl.Do<TSource>(source, onNext); |
| 190 |
} |
| 191 |
|
| 192 |
/// <summary> |
| 193 |
/// Invokes an action for each element in the observable sequence and invokes an action upon graceful termination of the observable sequence. |
| 194 |
/// This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline. |
| 195 |
/// </summary> |
| 196 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 197 |
/// <param name="source">Source sequence.</param> |
| 198 |
/// <param name="onNext">Action to invoke for each element in the observable sequence.</param> |
| 199 |
/// <param name="onCompleted">Action to invoke upon graceful termination of the observable sequence.</param> |
| 200 |
/// <returns>The source sequence with the side-effecting behavior applied.</returns> |
| 201 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> or <paramref name="onCompleted"/> is null.</exception> |
| 202 |
public static IObservable<TSource> Do<TSource>(this IObservable<TSource> source, Action<TSource> onNext, Action onCompleted) |
| 203 |
{ |
| 204 |
if (source == null) |
| 205 |
throw new ArgumentNullException("source"); |
| 206 |
if (onNext == null) |
| 207 |
throw new ArgumentNullException("onNext"); |
| 208 |
if (onCompleted == null) |
| 209 |
throw new ArgumentNullException("onCompleted"); |
| 210 |
|
| 211 |
return s_impl.Do<TSource>(source, onNext, onCompleted); |
| 212 |
} |
| 213 |
|
| 214 |
/// <summary> |
| 215 |
/// Invokes an action for each element in the observable sequence and invokes an action upon exceptional termination of the observable sequence. |
| 216 |
/// This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline. |
| 217 |
/// </summary> |
| 218 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 219 |
/// <param name="source">Source sequence.</param> |
| 220 |
/// <param name="onNext">Action to invoke for each element in the observable sequence.</param> |
| 221 |
/// <param name="onError">Action to invoke upon exceptional termination of the observable sequence.</param> |
| 222 |
/// <returns>The source sequence with the side-effecting behavior applied.</returns> |
| 223 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> or <paramref name="onError"/> is null.</exception> |
| 224 |
public static IObservable<TSource> Do<TSource>(this IObservable<TSource> source, Action<TSource> onNext, Action<Exception> onError) |
| 225 |
{ |
| 226 |
if (source == null) |
| 227 |
throw new ArgumentNullException("source"); |
| 228 |
if (onNext == null) |
| 229 |
throw new ArgumentNullException("onNext"); |
| 230 |
if (onError == null) |
| 231 |
throw new ArgumentNullException("onError"); |
| 232 |
|
| 233 |
return s_impl.Do<TSource>(source, onNext, onError); |
| 234 |
} |
| 235 |
|
| 236 |
/// <summary> |
| 237 |
/// Invokes an action for each element in the observable sequence and invokes an action upon graceful or exceptional termination of the observable sequence. |
| 238 |
/// This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline. |
| 239 |
/// </summary> |
| 240 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 241 |
/// <param name="source">Source sequence.</param> |
| 242 |
/// <param name="onNext">Action to invoke for each element in the observable sequence.</param> |
| 243 |
/// <param name="onError">Action to invoke upon exceptional termination of the observable sequence.</param> |
| 244 |
/// <param name="onCompleted">Action to invoke upon graceful termination of the observable sequence.</param> |
| 245 |
/// <returns>The source sequence with the side-effecting behavior applied.</returns> |
| 246 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="onNext"/> or <paramref name="onError"/> or <paramref name="onCompleted"/> is null.</exception> |
| 247 |
public static IObservable<TSource> Do<TSource>(this IObservable<TSource> source, Action<TSource> onNext, Action<Exception> onError, Action onCompleted) |
| 248 |
{ |
| 249 |
if (source == null) |
| 250 |
throw new ArgumentNullException("source"); |
| 251 |
if (onNext == null) |
| 252 |
throw new ArgumentNullException("onNext"); |
| 253 |
if (onError == null) |
| 254 |
throw new ArgumentNullException("onError"); |
| 255 |
if (onCompleted == null) |
| 256 |
throw new ArgumentNullException("onCompleted"); |
| 257 |
|
| 258 |
return s_impl.Do<TSource>(source, onNext, onError, onCompleted); |
| 259 |
} |
| 260 |
|
| 261 |
/// <summary> |
| 262 |
/// Invokes the observer's methods for each message in the source sequence. |
| 263 |
/// This method can be used for debugging, logging, etc. of query behavior by intercepting the message stream to run arbitrary actions for messages on the pipeline. |
| 264 |
/// </summary> |
| 265 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 266 |
/// <param name="source">Source sequence.</param> |
| 267 |
/// <param name="observer">Observer whose methods to invoke as part of the source sequence's observation.</param> |
| 268 |
/// <returns>The source sequence with the side-effecting behavior applied.</returns> |
| 269 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="observer"/> is null.</exception> |
| 270 |
public static IObservable<TSource> Do<TSource>(this IObservable<TSource> source, IObserver<TSource> observer) |
| 271 |
{ |
| 272 |
if (source == null) |
| 273 |
throw new ArgumentNullException("source"); |
| 274 |
if (observer == null) |
| 275 |
throw new ArgumentNullException("observer"); |
| 276 |
|
| 277 |
return s_impl.Do<TSource>(source, observer); |
| 278 |
} |
| 279 |
|
| 280 |
#endregion |
| 281 |
|
| 282 |
#region + Finally + |
| 283 |
|
| 284 |
/// <summary> |
| 285 |
/// Invokes a specified action after the source observable sequence terminates gracefully or exceptionally. |
| 286 |
/// </summary> |
| 287 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 288 |
/// <param name="source">Source sequence.</param> |
| 289 |
/// <param name="finallyAction">Action to invoke after the source observable sequence terminates.</param> |
| 290 |
/// <returns>Source sequence with the action-invoking termination behavior applied.</returns> |
| 291 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="finallyAction"/> is null.</exception> |
| 292 |
public static IObservable<TSource> Finally<TSource>(this IObservable<TSource> source, Action finallyAction) |
| 293 |
{ |
| 294 |
if (source == null) |
| 295 |
throw new ArgumentNullException("source"); |
| 296 |
if (finallyAction == null) |
| 297 |
throw new ArgumentNullException("finallyAction"); |
| 298 |
|
| 299 |
return s_impl.Finally<TSource>(source, finallyAction); |
| 300 |
} |
| 301 |
|
| 302 |
#endregion |
| 303 |
|
| 304 |
#region + IgnoreElements + |
| 305 |
|
| 306 |
/// <summary> |
| 307 |
/// Ignores all elements in an observable sequence leaving only the termination messages. |
| 308 |
/// </summary> |
| 309 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 310 |
/// <param name="source">Source sequence.</param> |
| 311 |
/// <returns>An empty observable sequence that signals termination, successful or exceptional, of the source sequence.</returns> |
| 312 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 313 |
public static IObservable<TSource> IgnoreElements<TSource>(this IObservable<TSource> source) |
| 314 |
{ |
| 315 |
if (source == null) |
| 316 |
throw new ArgumentNullException("source"); |
| 317 |
|
| 318 |
return s_impl.IgnoreElements<TSource>(source); |
| 319 |
} |
| 320 |
|
| 321 |
#endregion |
| 322 |
|
| 323 |
#region + Materialize + |
| 324 |
|
| 325 |
/// <summary> |
| 326 |
/// Materializes the implicit notifications of an observable sequence as explicit notification values. |
| 327 |
/// </summary> |
| 328 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 329 |
/// <param name="source">An observable sequence to get notification values for.</param> |
| 330 |
/// <returns>An observable sequence containing the materialized notification values from the source sequence.</returns> |
| 331 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 332 |
public static IObservable<Notification<TSource>> Materialize<TSource>(this IObservable<TSource> source) |
| 333 |
{ |
| 334 |
if (source == null) |
| 335 |
throw new ArgumentNullException("source"); |
| 336 |
|
| 337 |
return s_impl.Materialize<TSource>(source); |
| 338 |
} |
| 339 |
|
| 340 |
#endregion |
| 341 |
|
| 342 |
#region + Repeat + |
| 343 |
|
| 344 |
/// <summary> |
| 345 |
/// Repeats the observable sequence indefinitely. |
| 346 |
/// </summary> |
| 347 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 348 |
/// <param name="source">Observable sequence to repeat.</param> |
| 349 |
/// <returns>The observable sequence producing the elements of the given sequence repeatedly and sequentially.</returns> |
| 350 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 351 |
public static IObservable<TSource> Repeat<TSource>(this IObservable<TSource> source) |
| 352 |
{ |
| 353 |
if (source == null) |
| 354 |
throw new ArgumentNullException("source"); |
| 355 |
|
| 356 |
return s_impl.Repeat<TSource>(source); |
| 357 |
} |
| 358 |
|
| 359 |
/// <summary> |
| 360 |
/// Repeats the observable sequence a specified number of times. |
| 361 |
/// </summary> |
| 362 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 363 |
/// <param name="source">Observable sequence to repeat.</param> |
| 364 |
/// <param name="repeatCount">Number of times to repeat the sequence.</param> |
| 365 |
/// <returns>The observable sequence producing the elements of the given sequence repeatedly.</returns> |
| 366 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 367 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="repeatCount"/> is less than zero.</exception> |
| 368 |
public static IObservable<TSource> Repeat<TSource>(this IObservable<TSource> source, int repeatCount) |
| 369 |
{ |
| 370 |
if (source == null) |
| 371 |
throw new ArgumentNullException("source"); |
| 372 |
if (repeatCount < 0) |
| 373 |
throw new ArgumentOutOfRangeException("repeatCount"); |
| 374 |
|
| 375 |
return s_impl.Repeat<TSource>(source, repeatCount); |
| 376 |
} |
| 377 |
|
| 378 |
#endregion |
| 379 |
|
| 380 |
#region + Retry + |
| 381 |
|
| 382 |
/// <summary> |
| 383 |
/// Repeats the source observable sequence until it successfully terminates. |
| 384 |
/// </summary> |
| 385 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 386 |
/// <param name="source">Observable sequence to repeat until it successfully terminates.</param> |
| 387 |
/// <returns>An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.</returns> |
| 388 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 389 |
public static IObservable<TSource> Retry<TSource>(this IObservable<TSource> source) |
| 390 |
{ |
| 391 |
if (source == null) |
| 392 |
throw new ArgumentNullException("source"); |
| 393 |
|
| 394 |
return s_impl.Retry<TSource>(source); |
| 395 |
} |
| 396 |
|
| 397 |
/// <summary> |
| 398 |
/// Repeats the source observable sequence the specified number of times or until it successfully terminates. |
| 399 |
/// </summary> |
| 400 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 401 |
/// <param name="source">Observable sequence to repeat until it successfully terminates.</param> |
| 402 |
/// <param name="retryCount">Number of times to repeat the sequence.</param> |
| 403 |
/// <returns>An observable sequence producing the elements of the given sequence repeatedly until it terminates successfully.</returns> |
| 404 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 405 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="retryCount"/> is less than zero.</exception> |
| 406 |
public static IObservable<TSource> Retry<TSource>(this IObservable<TSource> source, int retryCount) |
| 407 |
{ |
| 408 |
if (source == null) |
| 409 |
throw new ArgumentNullException("source"); |
| 410 |
if (retryCount < 0) |
| 411 |
throw new ArgumentOutOfRangeException("retryCount"); |
| 412 |
|
| 413 |
return s_impl.Retry<TSource>(source, retryCount); |
| 414 |
} |
| 415 |
|
| 416 |
#endregion |
| 417 |
|
| 418 |
#region + Scan + |
| 419 |
|
| 420 |
/// <summary> |
| 421 |
/// Applies an accumulator function over an observable sequence and returns each intermediate result. The specified seed value is used as the initial accumulator value. |
| 422 |
/// For aggregation behavior with no intermediate results, see <see cref="Observable.Aggregate<TSource, Accumulate>"/>. |
| 423 |
/// </summary> |
| 424 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 425 |
/// <typeparam name="TAccumulate">The type of the result of the aggregation.</typeparam> |
| 426 |
/// <param name="source">An observable sequence to accumulate over.</param> |
| 427 |
/// <param name="seed">The initial accumulator value.</param> |
| 428 |
/// <param name="accumulator">An accumulator function to be invoked on each element.</param> |
| 429 |
/// <returns>An observable sequence containing the accumulated values.</returns> |
| 430 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="accumulator"/> is null.</exception> |
| 431 |
public static IObservable<TAccumulate> Scan<TSource, TAccumulate>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> accumulator) |
| 432 |
{ |
| 433 |
if (source == null) |
| 434 |
throw new ArgumentNullException("source"); |
| 435 |
if (accumulator == null) |
| 436 |
throw new ArgumentNullException("accumulator"); |
| 437 |
|
| 438 |
return s_impl.Scan<TSource, TAccumulate>(source, seed, accumulator); |
| 439 |
} |
| 440 |
|
| 441 |
/// <summary> |
| 442 |
/// Applies an accumulator function over an observable sequence and returns each intermediate result. |
| 443 |
/// For aggregation behavior with no intermediate results, see <see cref="Observable.Aggregate<TSource>"/>. |
| 444 |
/// </summary> |
| 445 |
/// <typeparam name="TSource">The type of the elements in the source sequence and the result of the aggregation.</typeparam> |
| 446 |
/// <param name="source">An observable sequence to accumulate over.</param> |
| 447 |
/// <param name="accumulator">An accumulator function to be invoked on each element.</param> |
| 448 |
/// <returns>An observable sequence containing the accumulated values.</returns> |
| 449 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="accumulator"/> is null.</exception> |
| 450 |
public static IObservable<TSource> Scan<TSource>(this IObservable<TSource> source, Func<TSource, TSource, TSource> accumulator) |
| 451 |
{ |
| 452 |
if (source == null) |
| 453 |
throw new ArgumentNullException("source"); |
| 454 |
if (accumulator == null) |
| 455 |
throw new ArgumentNullException("accumulator"); |
| 456 |
|
| 457 |
return s_impl.Scan<TSource>(source, accumulator); |
| 458 |
} |
| 459 |
|
| 460 |
#endregion |
| 461 |
|
| 462 |
#region + SkipLast + |
| 463 |
|
| 464 |
/// <summary> |
| 465 |
/// Bypasses a specified number of elements at the end of an observable sequence. |
| 466 |
/// </summary> |
| 467 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 468 |
/// <param name="source">Source sequence.</param> |
| 469 |
/// <param name="count">Number of elements to bypass at the end of the source sequence.</param> |
| 470 |
/// <returns>An observable sequence containing the source sequence elements except for the bypassed ones at the end.</returns> |
| 471 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 472 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than zero.</exception> |
| 473 |
/// <remarks> |
| 474 |
/// This operator accumulates a queue with a length enough to store the first <paramref name="count"/> elements. As more elements are |
| 475 |
/// received, elements are taken from the front of the queue and produced on the result sequence. This causes elements to be delayed. |
| 476 |
/// </remarks> |
| 477 |
public static IObservable<TSource> SkipLast<TSource>(this IObservable<TSource> source, int count) |
| 478 |
{ |
| 479 |
if (source == null) |
| 480 |
throw new ArgumentNullException("source"); |
| 481 |
if (count < 0) |
| 482 |
throw new ArgumentOutOfRangeException("count"); |
| 483 |
|
| 484 |
return s_impl.SkipLast<TSource>(source, count); |
| 485 |
} |
| 486 |
|
| 487 |
#endregion |
| 488 |
|
| 489 |
#region + StartWith + |
| 490 |
|
| 491 |
/// <summary> |
| 492 |
/// Prepends a sequence of values to an observable sequence. |
| 493 |
/// </summary> |
| 494 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 495 |
/// <param name="source">Source sequence to prepend values to.</param> |
| 496 |
/// <param name="values">Values to prepend to the specified sequence.</param> |
| 497 |
/// <returns>The source sequence prepended with the specified values.</returns> |
| 498 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="values"/> is null.</exception> |
| 499 |
public static IObservable<TSource> StartWith<TSource>(this IObservable<TSource> source, params TSource[] values) |
| 500 |
{ |
| 501 |
if (source == null) |
| 502 |
throw new ArgumentNullException("source"); |
| 503 |
if (values == null) |
| 504 |
throw new ArgumentNullException("values"); |
| 505 |
|
| 506 |
return s_impl.StartWith<TSource>(source, values); |
| 507 |
} |
| 508 |
|
| 509 |
/// <summary> |
| 510 |
/// Prepends a sequence of values to an observable sequence. |
| 511 |
/// </summary> |
| 512 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 513 |
/// <param name="source">Source sequence to prepend values to.</param> |
| 514 |
/// <param name="values">Values to prepend to the specified sequence.</param> |
| 515 |
/// <returns>The source sequence prepended with the specified values.</returns> |
| 516 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="values"/> is null.</exception> |
| 517 |
public static IObservable<TSource> StartWith<TSource>(this IObservable<TSource> source, IEnumerable<TSource> values) |
| 518 |
{ |
| 519 |
if (source == null) |
| 520 |
throw new ArgumentNullException("source"); |
| 521 |
if (values == null) |
| 522 |
throw new ArgumentNullException("values"); |
| 523 |
|
| 524 |
TSource[] valueArray = values as TSource[]; |
| 525 |
if (valueArray == null) |
| 526 |
{ |
| 527 |
List<TSource> valueList = new List<TSource>(values); |
| 528 |
valueArray = valueList.ToArray(); |
| 529 |
} |
| 530 |
return s_impl.StartWith<TSource>(source, valueArray); |
| 531 |
} |
| 532 |
|
| 533 |
/// <summary> |
| 534 |
/// Prepends a sequence of values to an observable sequence. |
| 535 |
/// </summary> |
| 536 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 537 |
/// <param name="source">Source sequence to prepend values to.</param> |
| 538 |
/// <param name="scheduler">Scheduler to emit the prepended values on.</param> |
| 539 |
/// <param name="values">Values to prepend to the specified sequence.</param> |
| 540 |
/// <returns>The source sequence prepended with the specified values.</returns> |
| 541 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> or <paramref name="values"/> is null.</exception> |
| 542 |
public static IObservable<TSource> StartWith<TSource>(this IObservable<TSource> source, IScheduler scheduler, params TSource[] values) |
| 543 |
{ |
| 544 |
if (source == null) |
| 545 |
throw new ArgumentNullException("source"); |
| 546 |
if (scheduler == null) |
| 547 |
throw new ArgumentNullException("scheduler"); |
| 548 |
if (values == null) |
| 549 |
throw new ArgumentNullException("values"); |
| 550 |
|
| 551 |
return s_impl.StartWith<TSource>(source, scheduler, values); |
| 552 |
} |
| 553 |
|
| 554 |
/// <summary> |
| 555 |
/// Prepends a sequence of values to an observable sequence. |
| 556 |
/// </summary> |
| 557 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 558 |
/// <param name="source">Source sequence to prepend values to.</param> |
| 559 |
/// <param name="scheduler">Scheduler to emit the prepended values on.</param> |
| 560 |
/// <param name="values">Values to prepend to the specified sequence.</param> |
| 561 |
/// <returns>The source sequence prepended with the specified values.</returns> |
| 562 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> or <paramref name="values"/> is null.</exception> |
| 563 |
public static IObservable<TSource> StartWith<TSource>(this IObservable<TSource> source, IScheduler scheduler, IEnumerable<TSource> values) |
| 564 |
{ |
| 565 |
if (source == null) |
| 566 |
throw new ArgumentNullException("source"); |
| 567 |
if (scheduler == null) |
| 568 |
throw new ArgumentNullException("scheduler"); |
| 569 |
if (values == null) |
| 570 |
throw new ArgumentNullException("values"); |
| 571 |
|
| 572 |
TSource[] valueArray = values as TSource[]; |
| 573 |
if (valueArray == null) |
| 574 |
{ |
| 575 |
List<TSource> valueList = new List<TSource>(values); |
| 576 |
valueArray = valueList.ToArray(); |
| 577 |
} |
| 578 |
return s_impl.StartWith<TSource>(source, scheduler, valueArray); |
| 579 |
} |
| 580 |
|
| 581 |
#endregion |
| 582 |
|
| 583 |
#region + TakeLast + |
| 584 |
|
| 585 |
/// <summary> |
| 586 |
/// Returns a specified number of contiguous elements from the end of an observable sequence. |
| 587 |
/// </summary> |
| 588 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 589 |
/// <param name="source">Source sequence.</param> |
| 590 |
/// <param name="count">Number of elements to take from the end of the source sequence.</param> |
| 591 |
/// <returns>An observable sequence containing the specified number of elements from the end of the source sequence.</returns> |
| 592 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 593 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than zero.</exception> |
| 594 |
/// <remarks> |
| 595 |
/// This operator accumulates a buffer with a length enough to store elements <paramref name="count"/> elements. Upon completion of |
| 596 |
/// the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed. |
| 597 |
/// </remarks> |
| 598 |
public static IObservable<TSource> TakeLast<TSource>(this IObservable<TSource> source, int count) |
| 599 |
{ |
| 600 |
if (source == null) |
| 601 |
throw new ArgumentNullException("source"); |
| 602 |
if (count < 0) |
| 603 |
throw new ArgumentOutOfRangeException("count"); |
| 604 |
|
| 605 |
return s_impl.TakeLast<TSource>(source, count); |
| 606 |
} |
| 607 |
|
| 608 |
/// <summary> |
| 609 |
/// Returns a specified number of contiguous elements from the end of an observable sequence, using the specified scheduler to drain the queue. |
| 610 |
/// </summary> |
| 611 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 612 |
/// <param name="source">Source sequence.</param> |
| 613 |
/// <param name="count">Number of elements to take from the end of the source sequence.</param> |
| 614 |
/// <param name="scheduler">Scheduler used to drain the queue upon completion of the source sequence.</param> |
| 615 |
/// <returns>An observable sequence containing the specified number of elements from the end of the source sequence.</returns> |
| 616 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="scheduler"/> is null.</exception> |
| 617 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than zero.</exception> |
| 618 |
/// <remarks> |
| 619 |
/// This operator accumulates a buffer with a length enough to store elements <paramref name="count"/> elements. Upon completion of |
| 620 |
/// the source sequence, this buffer is drained on the result sequence. This causes the elements to be delayed. |
| 621 |
/// </remarks> |
| 622 |
public static IObservable<TSource> TakeLast<TSource>(this IObservable<TSource> source, int count, IScheduler scheduler) |
| 623 |
{ |
| 624 |
if (source == null) |
| 625 |
throw new ArgumentNullException("source"); |
| 626 |
if (count < 0) |
| 627 |
throw new ArgumentOutOfRangeException("count"); |
| 628 |
if (scheduler == null) |
| 629 |
throw new ArgumentNullException("scheduler"); |
| 630 |
|
| 631 |
return s_impl.TakeLast<TSource>(source, count, scheduler); |
| 632 |
} |
| 633 |
|
| 634 |
#endregion |
| 635 |
|
| 636 |
#region + TakeLastBuffer + |
| 637 |
|
| 638 |
/// <summary> |
| 639 |
/// Returns a list with the specified number of contiguous elements from the end of an observable sequence. |
| 640 |
/// </summary> |
| 641 |
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam> |
| 642 |
/// <param name="source">Source sequence.</param> |
| 643 |
/// <param name="count">Number of elements to take from the end of the source sequence.</param> |
| 644 |
/// <returns>An observable sequence containing a single list with the specified number of elements from the end of the source sequence.</returns> |
| 645 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 646 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than zero.</exception> |
| 647 |
/// <remarks> |
| 648 |
/// This operator accumulates a buffer with a length enough to store <paramref name="count"/> elements. Upon completion of the |
| 649 |
/// source sequence, this buffer is produced on the result sequence. |
| 650 |
/// </remarks> |
| 651 |
public static IObservable<IList<TSource>> TakeLastBuffer<TSource>(this IObservable<TSource> source, int count) |
| 652 |
{ |
| 653 |
if (source == null) |
| 654 |
throw new ArgumentNullException("source"); |
| 655 |
if (count < 0) |
| 656 |
throw new ArgumentOutOfRangeException("count"); |
| 657 |
|
| 658 |
return s_impl.TakeLastBuffer<TSource>(source, count); |
| 659 |
} |
| 660 |
|
| 661 |
#endregion |
| 662 |
|
| 663 |
#region + Window + |
| 664 |
|
| 665 |
/// <summary> |
| 666 |
/// Projects each element of an observable sequence into consecutive non-overlapping windows which are produced based on element count information. |
| 667 |
/// </summary> |
| 668 |
/// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam> |
| 669 |
/// <param name="source">Source sequence to produce windows over.</param> |
| 670 |
/// <param name="count">Length of each window.</param> |
| 671 |
/// <returns>An observable sequence of windows.</returns> |
| 672 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 673 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> is less than or equal to zero.</exception> |
| 674 |
public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, int count) |
| 675 |
{ |
| 676 |
if (source == null) |
| 677 |
throw new ArgumentNullException("source"); |
| 678 |
if (count <= 0) |
| 679 |
throw new ArgumentOutOfRangeException("count"); |
| 680 |
|
| 681 |
return s_impl.Window<TSource>(source, count); |
| 682 |
} |
| 683 |
|
| 684 |
/// <summary> |
| 685 |
/// Projects each element of an observable sequence into zero or more windows which are produced based on element count information. |
| 686 |
/// </summary> |
| 687 |
/// <typeparam name="TSource">The type of the elements in the source sequence, and in the windows in the result sequence.</typeparam> |
| 688 |
/// <param name="source">Source sequence to produce windows over.</param> |
| 689 |
/// <param name="count">Length of each window.</param> |
| 690 |
/// <param name="skip">Number of elements to skip between creation of consecutive windows.</param> |
| 691 |
/// <returns>An observable sequence of windows.</returns> |
| 692 |
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception> |
| 693 |
/// <exception cref="ArgumentOutOfRangeException"><paramref name="count"/> or <paramref name="skip"/> is less than or equal to zero.</exception> |
| 694 |
public static IObservable<IObservable<TSource>> Window<TSource>(this IObservable<TSource> source, int count, int skip) |
| 695 |
{ |
| 696 |
if (source == null) |
| 697 |
throw new ArgumentNullException("source"); |
| 698 |
if (count <= 0) |
| 699 |
throw new ArgumentOutOfRangeException("count"); |
| 700 |
if (skip <= 0) |
| 701 |
throw new ArgumentOutOfRangeException("skip"); |
| 702 |
|
| 703 |
return s_impl.Window<TSource>(source, count, skip); |
| 704 |
} |
| 705 |
|
| 706 |
#endregion |
| 707 |
} |
| 708 |
} |