import { identityAsync } from '../util/identity' ; import { wrapWithAbort } from './operators/withabort' ; import { throwIfAborted } from '../aborterror' ; import { MathOptions } from './mathoptions' ; param { AsyncIterable < number > } source param { MathOptions < number > } options returns { Promise < number > } export async function sum ( source , options ? ) ; template T param { AsyncIterable < T > } source param { MathOptions < T > } options returns { Promise < number > } export async function sum < T > ( source , options ? ) ; param { AsyncIterable < any > } source param { MathOptions < any > } options returns { Promise < number > } export async function sum ( source , options ? ) { const { [ 'selector' ] : selector = identityAsync as any , [ 'signal' ] : signal , [ 'thisArg' ] : thisArg , } = options || { } ; throwIfAborted ( signal ) ; let value = 0 ; for await ( const item of wrapWithAbort ( source , signal ) ) { value += await selector . call ( thisArg , item , signal ) ; } return value ; }