sumBy() function
返回对每个元素应用 f 后的值之和。空 iterable 返回 0。
Signature:
typescript
function sumBy<A>(f: (a: A) => number, iterable: Iterable<A>): number;
function sumBy<A>(
f: (a: A) => number,
iterable: AsyncIterable<A>,
): Promise<number>;Example
ts
sumBy(
(a) => a.price,
[
{ name: "apple", price: 100 },
{ name: "banana", price: 200 },
],
); // 300
sumBy((a) => a.price, []); // 0
pipe(
[{ price: 100 }, { price: 200 }],
sumBy((a) => a.price),
); // 300