UNPKG

1.38 kBTypeScriptView Raw
1import { MonoTypeOperatorFunction } from '../types';
2/**
3 * The Max operator operates on an Observable that emits numbers (or items that can be compared with a provided function),
4 * and when source Observable completes it emits a single item: the item with the largest value.
5 *
6 * ![](max.png)
7 *
8 * ## Examples
9 * Get the maximal value of a series of numbers
10 * ```ts
11 * import { of } from 'rxjs';
12 * import { max } from 'rxjs/operators';
13 *
14 * of(5, 4, 7, 2, 8).pipe(
15 * max(),
16 * )
17 * .subscribe(x => console.log(x)); // -> 8
18 * ```
19 *
20 * Use a comparer function to get the maximal item
21 * ```typescript
22 * import { of } from 'rxjs';
23 * import { max } from 'rxjs/operators';
24 *
25 * interface Person {
26 * age: number,
27 * name: string
28 * }
29 *of(
30 * {age: 7, name: 'Foo'},
31 * {age: 5, name: 'Bar'},
32 * {age: 9, name: 'Beer'},
33 * ).pipe(
34 * max<Person>((a: Person, b: Person) => a.age < b.age ? -1 : 1),
35 * )
36 * .subscribe((x: Person) => console.log(x.name)); // -> 'Beer'
37 * ```
38 *
39 * @see {@link min}
40 *
41 * @param {Function} [comparer] - Optional comparer function that it will use instead of its default to compare the
42 * value of two items.
43 * @return A function that returns an Observable that emits item with the
44 * largest value.
45 */
46export declare function max<T>(comparer?: (x: T, y: T) => number): MonoTypeOperatorFunction<T>;
47//# sourceMappingURL=max.d.ts.map
\No newline at end of file