(collection: Iterable<BigDecimal>): BigDecimalTakes an Iterable of BigDecimals and returns their sum as a single BigDecimal.
When to use
Use when you need to aggregate decimal quantities with decimal precision instead of converting through JavaScript numbers.
Example (Adding multiple decimals)
import { BigDecimal } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
BigDecimal.sumAll([BigDecimal.fromStringUnsafe("2"), BigDecimal.fromStringUnsafe("3"), BigDecimal.fromStringUnsafe("4")]),
BigDecimal.fromStringUnsafe("9")
)mathsum
Source effect/BigDecimal.ts:3467 lines
export const const sumAll: (
collection: Iterable<BigDecimal>
) => BigDecimal
Takes an Iterable of BigDecimals and returns their sum as a single BigDecimal.
When to use
Use when you need to aggregate decimal quantities with decimal precision
instead of converting through JavaScript numbers.
Example (Adding multiple decimals)
import { BigDecimal } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(
BigDecimal.sumAll([BigDecimal.fromStringUnsafe("2"), BigDecimal.fromStringUnsafe("3"), BigDecimal.fromStringUnsafe("4")]),
BigDecimal.fromStringUnsafe("9")
)
sumAll = (collection: Iterable<BigDecimal>collection: interface Iterable<T, TReturn = any, TNext = any>Iterable<BigDecimal>): BigDecimal => {
let let out: BigDecimallet out: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
out: BigDecimal = const zero: BigDecimalconst zero: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
zero
for (const const n: BigDecimalconst n: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
n of collection: Iterable<BigDecimal>collection) {
let out: BigDecimallet out: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
out = const sum: {
(that: BigDecimal): (
self: BigDecimal
) => BigDecimal
(self: BigDecimal, that: BigDecimal): BigDecimal
}
sum(let out: BigDecimallet out: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
out, const n: BigDecimalconst n: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
n)
}
return let out: BigDecimallet out: {
value: bigint;
scale: number;
normalized: BigDecimal;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
toString: () => string;
toJSON: () => unknown;
}
out
}