rx.coincidence.es6.d.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. declare module Rx {
  2. export interface Observable<T> {
  3. /**
  4. * Correlates the elements of two sequences based on overlapping durations.
  5. *
  6. * @param {Observable} right The right observable sequence to join elements for.
  7. * @param {Function} leftDurationSelector A function to select the duration (expressed as an observable sequence) of each element of the left observable sequence, used to determine overlap.
  8. * @param {Function} rightDurationSelector A function to select the duration (expressed as an observable sequence) of each element of the right observable sequence, used to determine overlap.
  9. * @param {Function} resultSelector A function invoked to compute a result element for any two overlapping elements of the left and right observable sequences. The parameters passed to the function correspond with the elements from the left and right source sequences for which overlap occurs.
  10. * @returns {Observable} An observable sequence that contains result elements computed from source elements that have an overlapping duration.
  11. */
  12. join<TRight, TDurationLeft, TDurationRight, TResult>(
  13. right: Observable<TRight>,
  14. leftDurationSelector: (leftItem: T) => Observable<TDurationLeft>,
  15. rightDurationSelector: (rightItem: TRight) => Observable<TDurationRight>,
  16. resultSelector: (leftItem: T, rightItem: TRight) => TResult): Observable<TResult>;
  17. }
  18. export interface Observable<T> {
  19. /**
  20. * Groups the elements of an observable sequence according to a specified key selector function.
  21. * 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
  22. * key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
  23. *
  24. * @example
  25. * var res = observable.groupByUntil(function (x) { return x.id; }, null, function () { return Rx.Observable.never(); });
  26. * 2 - observable.groupBy(function (x) { return x.id; }), function (x) { return x.name; }, function () { return Rx.Observable.never(); });
  27. * 3 - observable.groupBy(function (x) { return x.id; }), function (x) { return x.name; }, function () { return Rx.Observable.never(); }, function (x) { return x.toString(); });
  28. * @param {Function} keySelector A function to extract the key for each element.
  29. * @param {Function} durationSelector A function to signal the expiration of a group.
  30. * @returns {Observable}
  31. * A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
  32. * 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.
  33. *
  34. */
  35. groupByUntil<TKey, TDuration>(keySelector: (value: T) => TKey, skipElementSelector: boolean, durationSelector: (group: GroupedObservable<TKey, T>) => Observable<TDuration>, keySerializer?: (key: TKey) => string): Observable<GroupedObservable<TKey, T>>;
  36. /**
  37. * Groups the elements of an observable sequence according to a specified key selector function.
  38. * 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
  39. * key value as a reclaimed group occurs, the group will be reborn with a new lifetime request.
  40. *
  41. * @example
  42. * var res = observable.groupByUntil(function (x) { return x.id; }, null, function () { return Rx.Observable.never(); });
  43. * 2 - observable.groupBy(function (x) { return x.id; }), function (x) { return x.name; }, function () { return Rx.Observable.never(); });
  44. * 3 - observable.groupBy(function (x) { return x.id; }), function (x) { return x.name; }, function () { return Rx.Observable.never(); }, function (x) { return x.toString(); });
  45. * @param {Function} keySelector A function to extract the key for each element.
  46. * @param {Function} durationSelector A function to signal the expiration of a group.
  47. * @returns {Observable}
  48. * A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
  49. * 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.
  50. *
  51. */
  52. groupByUntil<TKey, TElement, TDuration>(keySelector: (value: T) => TKey, elementSelector: (value: T) => TElement, durationSelector: (group: GroupedObservable<TKey, TElement>) => Observable<TDuration>, keySerializer?: (key: TKey) => string): Observable<GroupedObservable<TKey, TElement>>;
  53. }
  54. export interface Observable<T> {
  55. /**
  56. * Correlates the elements of two sequences based on overlapping durations, and groups the results.
  57. *
  58. * @param {Observable} right The right observable sequence to join elements for.
  59. * @param {Function} leftDurationSelector A function to select the duration (expressed as an observable sequence) of each element of the left observable sequence, used to determine overlap.
  60. * @param {Function} rightDurationSelector A function to select the duration (expressed as an observable sequence) of each element of the right observable sequence, used to determine overlap.
  61. * @param {Function} resultSelector A function invoked to compute a result element for any element of the left sequence with overlapping elements from the right observable sequence. The first parameter passed to the function is an element of the left sequence. The second parameter passed to the function is an observable sequence with elements from the right sequence that overlap with the left sequence's element.
  62. * @returns {Observable} An observable sequence that contains result elements computed from source elements that have an overlapping duration.
  63. */
  64. groupJoin<TRight, TDurationLeft, TDurationRight, TResult>(
  65. right: Observable<TRight>,
  66. leftDurationSelector: (leftItem: T) => Observable<TDurationLeft>,
  67. rightDurationSelector: (rightItem: TRight) => Observable<TDurationRight>,
  68. resultSelector: (leftItem: T, rightItem: Observable<TRight>) => TResult): Observable<TResult>;
  69. }
  70. export interface Observable<T> {
  71. /**
  72. * Projects each element of an observable sequence into zero or more buffers.
  73. * @param {Mixed} bufferOpeningsOrClosingSelector Observable sequence whose elements denote the creation of new windows, or, a function invoked to define the boundaries of the produced windows (a new window is started when the previous one is closed, resulting in non-overlapping windows).
  74. * @param {Function} [bufferClosingSelector] A function invoked to define the closing of each produced window. If a closing selector function is specified for the first parameter, this parameter is ignored.
  75. * @returns {Observable} An observable sequence of windows.
  76. */
  77. buffer<TBufferOpening>(bufferOpenings: Observable<TBufferOpening>): Observable<T[]>;
  78. /**
  79. * Projects each element of an observable sequence into zero or more buffers.
  80. * @param {Mixed} bufferOpeningsOrClosingSelector Observable sequence whose elements denote the creation of new windows, or, a function invoked to define the boundaries of the produced windows (a new window is started when the previous one is closed, resulting in non-overlapping windows).
  81. * @param {Function} [bufferClosingSelector] A function invoked to define the closing of each produced window. If a closing selector function is specified for the first parameter, this parameter is ignored.
  82. * @returns {Observable} An observable sequence of windows.
  83. */
  84. buffer<TBufferClosing>(bufferClosingSelector: () => Observable<TBufferClosing>): Observable<T[]>;
  85. /**
  86. * Projects each element of an observable sequence into zero or more buffers.
  87. * @param {Mixed} bufferOpeningsOrClosingSelector Observable sequence whose elements denote the creation of new windows, or, a function invoked to define the boundaries of the produced windows (a new window is started when the previous one is closed, resulting in non-overlapping windows).
  88. * @param {Function} [bufferClosingSelector] A function invoked to define the closing of each produced window. If a closing selector function is specified for the first parameter, this parameter is ignored.
  89. * @returns {Observable} An observable sequence of windows.
  90. */
  91. buffer<TBufferOpening, TBufferClosing>(bufferOpenings: Observable<TBufferOpening>, bufferClosingSelector: () => Observable<TBufferClosing>): Observable<T[]>;
  92. }
  93. export interface Observable<T> {
  94. /**
  95. * Projects each element of an observable sequence into zero or more windows.
  96. *
  97. * @param {Mixed} windowOpeningsOrClosingSelector Observable sequence whose elements denote the creation of new windows, or, a function invoked to define the boundaries of the produced windows (a new window is started when the previous one is closed, resulting in non-overlapping windows).
  98. * @param {Function} [windowClosingSelector] A function invoked to define the closing of each produced window. If a closing selector function is specified for the first parameter, this parameter is ignored.
  99. * @returns {Observable} An observable sequence of windows.
  100. */
  101. window<TWindowOpening>(windowOpenings: Observable<TWindowOpening>): Observable<Observable<T>>;
  102. /**
  103. * Projects each element of an observable sequence into zero or more windows.
  104. *
  105. * @param {Mixed} windowOpeningsOrClosingSelector Observable sequence whose elements denote the creation of new windows, or, a function invoked to define the boundaries of the produced windows (a new window is started when the previous one is closed, resulting in non-overlapping windows).
  106. * @param {Function} [windowClosingSelector] A function invoked to define the closing of each produced window. If a closing selector function is specified for the first parameter, this parameter is ignored.
  107. * @returns {Observable} An observable sequence of windows.
  108. */
  109. window<TWindowClosing>(windowClosingSelector: () => Observable<TWindowClosing>): Observable<Observable<T>>;
  110. /**
  111. * Projects each element of an observable sequence into zero or more windows.
  112. *
  113. * @param {Mixed} windowOpeningsOrClosingSelector Observable sequence whose elements denote the creation of new windows, or, a function invoked to define the boundaries of the produced windows (a new window is started when the previous one is closed, resulting in non-overlapping windows).
  114. * @param {Function} [windowClosingSelector] A function invoked to define the closing of each produced window. If a closing selector function is specified for the first parameter, this parameter is ignored.
  115. * @returns {Observable} An observable sequence of windows.
  116. */
  117. window<TWindowOpening, TWindowClosing>(windowOpenings: Observable<TWindowOpening>, windowClosingSelector: () => Observable<TWindowClosing>): Observable<Observable<T>>;
  118. }
  119. export interface Observable<T> {
  120. /**
  121. * Returns a new observable that triggers on the second and subsequent triggerings of the input observable.
  122. * The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair.
  123. * The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.
  124. * @returns {Observable} An observable that triggers on successive pairs of observations from the input observable as an array.
  125. */
  126. pairwise(): Observable<[T, T]>;
  127. }
  128. export interface Observable<T> {
  129. /**
  130. * Returns two observables which partition the observations of the source by the given function.
  131. * The first will trigger observations for those values for which the predicate returns true.
  132. * The second will trigger observations for those values where the predicate returns false.
  133. * The predicate is executed once for each subscribed observer.
  134. * Both also propagate all error observations arising from the source and each completes
  135. * when the source completes.
  136. * @param {Function} predicate
  137. * The function to determine which output Observable will trigger a particular observation.
  138. * @returns {Array}
  139. * An array of observables. The first triggers when the predicate returns true,
  140. * and the second triggers when the predicate returns false.
  141. */
  142. partition(predicate: _Predicate<T>, thisArg?: any): [Observable<T>, Observable<T>];
  143. }
  144. export interface Observable<T> {
  145. /**
  146. * 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.
  147. *
  148. * @example
  149. * var res = observable.groupBy(function (x) { return x.id; });
  150. * 2 - observable.groupBy(function (x) { return x.id; }), function (x) { return x.name; });
  151. * 3 - observable.groupBy(function (x) { return x.id; }), function (x) { return x.name; }, function (x) { return x.toString(); });
  152. * @param {Function} keySelector A function to extract the key for each element.
  153. * @param {Function} [elementSelector] A function to map each source element to an element in an observable group.
  154. * @returns {Observable} A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
  155. */
  156. groupBy<TKey, TElement>(keySelector: (value: T) => TKey, skipElementSelector?: boolean, keySerializer?: (key: TKey) => string): Observable<GroupedObservable<TKey, T>>;
  157. /**
  158. * 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.
  159. *
  160. * @example
  161. * var res = observable.groupBy(function (x) { return x.id; });
  162. * 2 - observable.groupBy(function (x) { return x.id; }), function (x) { return x.name; });
  163. * 3 - observable.groupBy(function (x) { return x.id; }), function (x) { return x.name; }, function (x) { return x.toString(); });
  164. * @param {Function} keySelector A function to extract the key for each element.
  165. * @param {Function} [elementSelector] A function to map each source element to an element in an observable group.
  166. * @returns {Observable} A sequence of observable groups, each of which corresponds to a unique key value, containing all elements that share that same key value.
  167. */
  168. groupBy<TKey, TElement>(keySelector: (value: T) => TKey, elementSelector: (value: T) => TElement, keySerializer?: (key: TKey) => string): Observable<GroupedObservable<TKey, TElement>>;
  169. }
  170. export interface GroupedObservable<TKey, TElement> extends Observable<TElement> {
  171. key: TKey;
  172. underlyingObservable: Observable<TElement>;
  173. }
  174. }
  175. declare module "rx.coincidence" { export = Rx; }