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