1 import { reduce } from './reduce';
2 import { MonoTypeOperatorFunction } from '../types';
5 * The Min operator operates on an Observable that emits numbers (or items that can be compared with a provided function),
6 * and when source Observable completes it emits a single item: the item with the smallest value.
11 * Get the minimal value of a series of numbers
13 * import { of } from 'rxjs';
14 * import { min } from 'rxjs/operators';
16 * of(5, 4, 7, 2, 8).pipe(
19 * .subscribe(x => console.log(x)); // -> 2
22 * Use a comparer function to get the minimal item
24 * import { of } from 'rxjs';
25 * import { min } from 'rxjs/operators';
32 * {age: 7, name: 'Foo'},
33 * {age: 5, name: 'Bar'},
34 * {age: 9, name: 'Beer'},
36 * min<Person>( (a: Person, b: Person) => a.age < b.age ? -1 : 1),
38 * .subscribe((x: Person) => console.log(x.name)); // -> 'Bar'
42 * @param {Function} [comparer] - Optional comparer function that it will use instead of its default to compare the
44 * @return {Observable<R>} An Observable that emits item with the smallest value.
48 export function min<T>(comparer?: (x: T, y: T) => number): MonoTypeOperatorFunction<T> {
49 const min: (x: T, y: T) => T = (typeof comparer === 'function')
50 ? (x, y) => comparer(x, y) < 0 ? x : y
51 : (x, y) => x < y ? x : y;