import { equalityComparer } from '../util/comparer' ; import { identity } from '../util/identity' ; import { ExtremaOptions } from './extremaoptions' ; template TSource param { Iterable < TSource > } source param { ExtremaByOptions < TKey > } options returns { TResult } export function min < TSource , TResult = TSource > ( source , options ? ) { const { [ 'comparer' ] : comparer = equalityComparer , [ 'selector' ] : selector = identity } = options || { } ; const it = source [ Symbol . iterator ] ( ) ; let next = it . next ( ) ; if ( next . done ) { throw new Error ( 'Sequence contains no elements' ) ; } let minValue = selector ( next . value ) ; while ( ! ( next = it . next ( ) ) . done ) { const current = selector ( next . value ) ; if ( comparer ( current , minValue ) < 0 ) { minValue = current ; } } return minValue ; }