import { ErrorString , InvalidOperationException } from "../../shared" ; param source param selector throws returns export const averageAsync = async < TSource > ( source , selector ) : Promise < number > => { let value ; let count ; for ( const item of source ) { value = ( value || 0 ) + await selector ( item ) ; count = ( count || 0 ) + 1 ; } if ( value === undefined ) { throw new InvalidOperationException ( ErrorString . NoElements ) ; } return value / ( count as number ) ; } ;