Code coverage report for src/operator/max.ts

Statements: 100% (6 / 6)      Branches: 100% (4 / 4)      Functions: 100% (2 / 2)      Lines: 100% (5 / 5)      Ignored: none     

All files » src/operator/ » max.ts
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  1                       1 22   10014 22    
import {Observable} from '../Observable';
import {ReduceOperator} from './reduce';
 
/**
 * The Max operator operates on an Observable that emits numbers (or items that can be evaluated as numbers),
 * and when source Observable completes it emits a single item: the item with the largest number.
 *
 * <img src="./img/max.png" width="100%">
 *
 * @param {Function} optional comparer function that it will use instead of its default to compare the value of two
 * items.
 * @returns {Observable} an Observable that emits item with the largest number.
 */
export function max<T>(comparer?: (value1: T, value2: T) => T): Observable<T> {
  const max: typeof comparer = (typeof comparer === 'function')
    ? comparer
    : (x, y) => x > y ? x : y;
  return this.lift(new ReduceOperator(max));
}