import { ErrorString , InvalidOperationException } from "../../shared" ; type MinFunc = { param source throws returns ( source ) : number ; param source param selector throws returns < TSource > ( source , selector ) : number ; } ; export const min = < TSource > ( source , selector ? ) : number => { if ( selector ) { return min2 ( source as Iterable < TSource > , selector ) ; } else { return min1 ( source as Iterable < number > ) ; } } ; const min1 = ( source ) => { let minItem = null ; for ( const item of source ) { minItem = Math . min ( minItem || Number . POSITIVE_INFINITY , item ) ; } if ( minItem === null ) { throw new InvalidOperationException ( ErrorString . NoElements ) ; } else { return minItem ; } } ; const min2 = < TSource > ( source , selector ) => { let minItem = null ; for ( const item of source ) { minItem = Math . min ( minItem || Number . POSITIVE_INFINITY , selector ( item ) ) ; } if ( minItem === null ) { throw new InvalidOperationException ( ErrorString . NoElements ) ; } else { return minItem ; } } ;