import { ErrorString , InvalidOperationException } from "../../shared" ; import { IParallelEnumerable } from "../../types" ; import { nextIterationAsync } from "./_nextIterationAsync" ; import { typeDataToArray } from "./_typeDataToArray" ; param source param selector throws returns export const averageAsync = async < TSource > ( source , selector ) : Promise < number > => { const nextIter = nextIterationAsync ( source , selector ) ; const values = await typeDataToArray ( nextIter ) ; if ( values . length === 0 ) { throw new InvalidOperationException ( ErrorString . NoElements ) ; } let value = 0 ; for ( const selectedValue of values ) { value += selectedValue ; } return value / values . length ; } ;