Observable.Joins.cs 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. using System.Collections.Generic;
  3. using System.Reactive.Disposables;
  4. using System.Reactive.Joins;
  5. namespace System.Reactive.Linq
  6. {
  7. public static partial class Observable
  8. {
  9. #region And
  10. /// <summary>
  11. /// Creates a pattern that matches when both observable sequences have an available element.
  12. /// </summary>
  13. /// <typeparam name="TLeft">The type of the elements in the left sequence.</typeparam>
  14. /// <typeparam name="TRight">The type of the elements in the right sequence.</typeparam>
  15. /// <param name="left">Observable sequence to match with the right sequence.</param>
  16. /// <param name="right">Observable sequence to match with the left sequence.</param>
  17. /// <returns>Pattern object that matches when both observable sequences have an available element.</returns>
  18. /// <exception cref="ArgumentNullException"><paramref name="left"/> or <paramref name="right"/> is null.</exception>
  19. public static Pattern<TLeft, TRight> And<TLeft, TRight>(this IObservable<TLeft> left, IObservable<TRight> right)
  20. {
  21. if (left == null)
  22. throw new ArgumentNullException("left");
  23. if (right == null)
  24. throw new ArgumentNullException("right");
  25. return s_impl.And<TLeft, TRight>(left, right);
  26. }
  27. #endregion
  28. #region Then
  29. /// <summary>
  30. /// Matches when the observable sequence has an available element and projects the element by invoking the selector function.
  31. /// </summary>
  32. /// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
  33. /// <typeparam name="TResult">The type of the elements in the result sequence, returned by the selector function.</typeparam>
  34. /// <param name="source">Observable sequence to apply the selector on.</param>
  35. /// <param name="selector">Selector that will be invoked for elements in the source sequence.</param>
  36. /// <returns>Plan that produces the projected results, to be fed (with other plans) to the When operator.</returns>
  37. /// <exception cref="ArgumentNullException"><paramref name="source"/> or <paramref name="selector"/> is null.</exception>
  38. public static Plan<TResult> Then<TSource, TResult>(this IObservable<TSource> source, Func<TSource, TResult> selector)
  39. {
  40. if (source == null)
  41. throw new ArgumentNullException("source");
  42. if (selector == null)
  43. throw new ArgumentNullException("selector");
  44. return s_impl.Then<TSource, TResult>(source, selector);
  45. }
  46. #endregion
  47. #region When
  48. /// <summary>
  49. /// Joins together the results from several patterns.
  50. /// </summary>
  51. /// <typeparam name="TResult">The type of the elements in the result sequence, obtained from the specified patterns.</typeparam>
  52. /// <param name="plans">A series of plans created by use of the Then operator on patterns.</param>
  53. /// <returns>An observable sequence with the results from matching several patterns.</returns>
  54. /// <exception cref="ArgumentNullException"><paramref name="plans"/> is null.</exception>
  55. public static IObservable<TResult> When<TResult>(params Plan<TResult>[] plans)
  56. {
  57. if (plans == null)
  58. throw new ArgumentNullException("plans");
  59. return s_impl.When<TResult>(plans);
  60. }
  61. /// <summary>
  62. /// Joins together the results from several patterns.
  63. /// </summary>
  64. /// <typeparam name="TResult">The type of the elements in the result sequence, obtained from the specified patterns.</typeparam>
  65. /// <param name="plans">A series of plans created by use of the Then operator on patterns.</param>
  66. /// <returns>An observable sequence with the results form matching several patterns.</returns>
  67. /// <exception cref="ArgumentNullException"><paramref name="plans"/> is null.</exception>
  68. public static IObservable<TResult> When<TResult>(this IEnumerable<Plan<TResult>> plans)
  69. {
  70. if (plans == null)
  71. throw new ArgumentNullException("plans");
  72. return s_impl.When<TResult>(plans);
  73. }
  74. #endregion
  75. }
  76. }