rx.aggregates.d.ts 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. declare module Rx {
  2. export interface Observable<T> {
  3. /**
  4. * Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
  5. * For aggregation behavior with incremental intermediate results, see Observable.scan.
  6. * @param {Function} accumulator An accumulator function to be invoked on each element.
  7. * @param {Any} [seed] The initial accumulator value.
  8. * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
  9. */
  10. reduce<TAcc>(accumulator: _Accumulator<T, TAcc>, seed?: TAcc): Observable<TAcc>;
  11. /**
  12. * Applies an accumulator function over an observable sequence, returning the result of the aggregation as a single element in the result sequence. The specified seed value is used as the initial accumulator value.
  13. * For aggregation behavior with incremental intermediate results, see Observable.scan.
  14. * @param {Function} accumulator An accumulator function to be invoked on each element.
  15. * @param {Any} [seed] The initial accumulator value.
  16. * @returns {Observable} An observable sequence containing a single element with the final accumulator value.
  17. */
  18. reduce(accumulator: _Accumulator<T, T>, seed?: T): Observable<T>;
  19. }
  20. export interface Observable<T> {
  21. /**
  22. * Determines whether any element of an observable sequence satisfies a condition if present, else if any items are in the sequence.
  23. * @param {Function} [predicate] A function to test each element for a condition.
  24. * @returns {Observable} An observable sequence containing a single element determining whether any elements in the source sequence pass the test in the specified predicate if given, else if any items are in the sequence.
  25. */
  26. some(predicate?: _Predicate<T>, thisArg?: any): Observable<boolean>; // alias for any
  27. }
  28. export interface Observable<T> {
  29. /**
  30. * Determines whether an observable sequence is empty.
  31. * @returns {Observable} An observable sequence containing a single element determining whether the source sequence is empty.
  32. */
  33. isEmpty(): Observable<boolean>;
  34. }
  35. export interface Observable<T> {
  36. /**
  37. * Determines whether all elements of an observable sequence satisfy a condition.
  38. * @param {Function} [predicate] A function to test each element for a condition.
  39. * @param {Any} [thisArg] Object to use as this when executing callback.
  40. * @returns {Observable} An observable sequence containing a single element determining whether all elements in the source sequence pass the test in the specified predicate.
  41. */
  42. every(predicate?: _Predicate<T>, thisArg?: any): Observable<boolean>; // alias for all
  43. }
  44. export interface Observable<T> {
  45. /**
  46. * Determines whether an observable sequence includes a specified element with an optional equality comparer.
  47. * @param searchElement The value to locate in the source sequence.
  48. * @param {Number} [fromIndex] An equality comparer to compare elements.
  49. * @returns {Observable} An observable sequence containing a single element determining whether the source sequence includes an element that has the specified value from the given index.
  50. */
  51. includes(value: T, comparer?: _Comparer<T, boolean>): Observable<boolean>;
  52. }
  53. export interface Observable<T> {
  54. /**
  55. * Returns an observable sequence containing a value that represents how many elements in the specified observable sequence satisfy a condition if provided, else the count of items.
  56. * @example
  57. * res = source.count();
  58. * res = source.count(function (x) { return x > 3; });
  59. * @param {Function} [predicate]A function to test each element for a condition.
  60. * @param {Any} [thisArg] Object to use as this when executing callback.
  61. * @returns {Observable} An observable sequence containing a single element with a number that represents how many elements in the input sequence satisfy the condition in the predicate function if provided, else the count of items in the sequence.
  62. */
  63. count(predicate?: _Predicate<T>, thisArg?: any): Observable<number>;
  64. }
  65. export interface Observable<T> {
  66. /**
  67. * Returns the first index at which a given element can be found in the observable sequence, or -1 if it is not present.
  68. * @param {Any} searchElement Element to locate in the array.
  69. * @param {Number} [fromIndex] The index to start the search. If not specified, defaults to 0.
  70. * @returns {Observable} And observable sequence containing the first index at which a given element can be found in the observable sequence, or -1 if it is not present.
  71. */
  72. indexOf(element: T, fromIndex?: number): Observable<number>;
  73. }
  74. export interface Observable<T> {
  75. /**
  76. * Computes the sum of a sequence of values that are obtained by invoking an optional transform function on each element of the input sequence, else if not specified computes the sum on each item in the sequence.
  77. * @param {Function} [selector] A transform function to apply to each element.
  78. * @param {Any} [thisArg] Object to use as this when executing callback.
  79. * @returns {Observable} An observable sequence containing a single element with the sum of the values in the source sequence.
  80. */
  81. sum(keySelector?: _Selector<T, number>, thisArg?: any): Observable<number>;
  82. }
  83. export interface Observable<T> {
  84. /**
  85. * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
  86. * @example
  87. * var res = source.minBy(function (x) { return x.value; });
  88. * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
  89. * @param {Function} keySelector Key selector function.
  90. * @param {Function} [comparer] Comparer used to compare key values.
  91. * @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
  92. */
  93. minBy<TKey>(keySelector: (item: T) => TKey, comparer: _Comparer<TKey, number>): Observable<T>;
  94. /**
  95. * Returns the elements in an observable sequence with the minimum key value according to the specified comparer.
  96. * @example
  97. * var res = source.minBy(function (x) { return x.value; });
  98. * var res = source.minBy(function (x) { return x.value; }, function (x, y) { return x - y; });
  99. * @param {Function} keySelector Key selector function.
  100. * @param {Function} [comparer] Comparer used to compare key values.
  101. * @returns {Observable} An observable sequence containing a list of zero or more elements that have a minimum key value.
  102. */
  103. minBy(keySelector: (item: T) => number): Observable<T>;
  104. }
  105. export interface Observable<T> {
  106. /**
  107. * Returns the minimum element in an observable sequence according to the optional comparer else a default greater than less than check.
  108. * @example
  109. * var res = source.min();
  110. * var res = source.min(function (x, y) { return x.value - y.value; });
  111. * @param {Function} [comparer] Comparer used to compare elements.
  112. * @returns {Observable} An observable sequence containing a single element with the minimum element in the source sequence.
  113. */
  114. min(comparer?: _Comparer<T, number>): Observable<number>;
  115. }
  116. export interface Observable<T> {
  117. /**
  118. * Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
  119. * @example
  120. * var res = source.maxBy(function (x) { return x.value; });
  121. * var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
  122. * @param {Function} keySelector Key selector function.
  123. * @param {Function} [comparer] Comparer used to compare key values.
  124. * @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
  125. */
  126. maxBy<TKey>(keySelector: (item: T) => TKey, comparer: _Comparer<TKey, number>): Observable<T>;
  127. /**
  128. * Returns the elements in an observable sequence with the maximum key value according to the specified comparer.
  129. * @example
  130. * var res = source.maxBy(function (x) { return x.value; });
  131. * var res = source.maxBy(function (x) { return x.value; }, function (x, y) { return x - y;; });
  132. * @param {Function} keySelector Key selector function.
  133. * @param {Function} [comparer] Comparer used to compare key values.
  134. * @returns {Observable} An observable sequence containing a list of zero or more elements that have a maximum key value.
  135. */
  136. maxBy(keySelector: (item: T) => number): Observable<T>;
  137. }
  138. export interface Observable<T> {
  139. /**
  140. * Returns the maximum value in an observable sequence according to the specified comparer.
  141. * @example
  142. * var res = source.max();
  143. * var res = source.max(function (x, y) { return x.value - y.value; });
  144. * @param {Function} [comparer] Comparer used to compare elements.
  145. * @returns {Observable} An observable sequence containing a single element with the maximum element in the source sequence.
  146. */
  147. max(comparer?: _Comparer<T, number>): Observable<number>;
  148. }
  149. export interface Observable<T> {
  150. /**
  151. * Computes the average of an observable sequence of values that are in the sequence or obtained by invoking a transform function on each element of the input sequence if present.
  152. * @param {Function} [selector] A transform function to apply to each element.
  153. * @param {Any} [thisArg] Object to use as this when executing callback.
  154. * @returns {Observable} An observable sequence containing a single element with the average of the sequence of values.
  155. */
  156. average(keySelector?: _Selector<T, number>, thisArg?: any): Observable<number>;
  157. }
  158. export interface Observable<T> {
  159. /**
  160. * Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.
  161. *
  162. * @example
  163. * var res = res = source.sequenceEqual([1,2,3]);
  164. * var res = res = source.sequenceEqual([{ value: 42 }], function (x, y) { return x.value === y.value; });
  165. * 3 - res = source.sequenceEqual(Rx.Observable.returnValue(42));
  166. * 4 - res = source.sequenceEqual(Rx.Observable.returnValue({ value: 42 }), function (x, y) { return x.value === y.value; });
  167. * @param {Observable} second Second observable sequence or array to compare.
  168. * @param {Function} [comparer] Comparer used to compare elements of both sequences.
  169. * @returns {Observable} An observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the specified equality comparer.
  170. */
  171. sequenceEqual(second: ObservableOrPromise<T> | ArrayOrIterable<T>, comparer?: _Comparer<T, boolean>): Observable<boolean>;
  172. /**
  173. * Determines whether two sequences are equal by comparing the elements pairwise using a specified equality comparer.
  174. *
  175. * @example
  176. * var res = res = source.sequenceEqual([1,2,3]);
  177. * var res = res = source.sequenceEqual([{ value: 42 }], function (x, y) { return x.value === y.value; });
  178. * 3 - res = source.sequenceEqual(Rx.Observable.returnValue(42));
  179. * 4 - res = source.sequenceEqual(Rx.Observable.returnValue({ value: 42 }), function (x, y) { return x.value === y.value; });
  180. * @param {Observable} second Second observable sequence or array to compare.
  181. * @param {Function} [comparer] Comparer used to compare elements of both sequences.
  182. * @returns {Observable} An observable sequence that contains a single element which indicates whether both sequences are of equal length and their corresponding elements are equal according to the specified equality comparer.
  183. */
  184. sequenceEqual<TOther>(second: ObservableOrPromise<T> | ArrayOrIterable<T>, comparer: _Comparer<T | TOther, boolean>): Observable<boolean>;
  185. }
  186. export interface Observable<T> {
  187. /**
  188. * Returns the element at a specified index in a sequence or default value if not found.
  189. * @param {Number} index The zero-based index of the element to retrieve.
  190. * @param {Any} [defaultValue] The default value to use if elementAt does not find a value.
  191. * @returns {Observable} An observable sequence that produces the element at the specified position in the source sequence.
  192. */
  193. elementAt(index: number): Observable<T>;
  194. }
  195. export interface Observable<T> {
  196. /**
  197. * Returns the only element of an observable sequence that satisfies the condition in the optional predicate, and reports an exception if there is not exactly one element in the observable sequence.
  198. * @param {Function} [predicate] A predicate function to evaluate for elements in the source sequence.
  199. * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
  200. * @returns {Observable} Sequence containing the single element in the observable sequence that satisfies the condition in the predicate.
  201. */
  202. single(predicate?: _Predicate<T>, thisArg?: any): Observable<T>;
  203. }
  204. export interface Observable<T> {
  205. /**
  206. * Returns the first element of an observable sequence that satisfies the condition in the predicate if present else the first item in the sequence.
  207. * @returns {Observable} Sequence containing the first element in the observable sequence that satisfies the condition in the predicate if provided, else the first item in the sequence.
  208. */
  209. first(predicate?: _Predicate<T>, thisArg?: any): Observable<T>;
  210. }
  211. export interface Observable<T> {
  212. /**
  213. * Returns the last element of an observable sequence that satisfies the condition in the predicate if specified, else the last element.
  214. * @returns {Observable} Sequence containing the last element in the observable sequence that satisfies the condition in the predicate.
  215. */
  216. last(predicate?: _Predicate<T>, thisArg?: any): Observable<T>;
  217. }
  218. export interface Observable<T> {
  219. /**
  220. * Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire Observable sequence.
  221. * @param {Function} predicate The predicate that defines the conditions of the element to search for.
  222. * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
  223. * @returns {Observable} An Observable sequence with the first element that matches the conditions defined by the specified predicate, if found; otherwise, undefined.
  224. */
  225. find(predicate: _Predicate<T>, thisArg?: any): Observable<T>;
  226. }
  227. export interface Observable<T> {
  228. /**
  229. * Searches for an element that matches the conditions defined by the specified predicate, and returns
  230. * an Observable sequence with the zero-based index of the first occurrence within the entire Observable sequence.
  231. * @param {Function} predicate The predicate that defines the conditions of the element to search for.
  232. * @param {Any} [thisArg] Object to use as `this` when executing the predicate.
  233. * @returns {Observable} An Observable sequence with the zero-based index of the first occurrence of an element that matches the conditions defined by match, if found; otherwise, –1.
  234. */
  235. findIndex(predicate: _Predicate<T>, thisArg?: any): Observable<number>;
  236. }
  237. }
  238. declare module "rx.aggregates" { export = Rx; }