Hyperlinkv0.8.0-beta.28

BigDecimal

BigDecimal.multiplyAllconsteffect/BigDecimal.ts:413
(collection: Iterable<BigDecimal>): BigDecimal

Takes an Iterable of BigDecimals and returns their multiplication as a single BigDecimal.

When to use

Use to multiply all BigDecimal values in an iterable.

Example (Multiplying multiple decimals)

import { BigDecimal } from "effect"
import * as assert from "node:assert"

assert.deepStrictEqual(
  BigDecimal.multiplyAll([BigDecimal.fromStringUnsafe("2"), BigDecimal.fromStringUnsafe("3"), BigDecimal.fromStringUnsafe("4")]),
  BigDecimal.fromStringUnsafe("24")
)
export const multiplyAll = (collection: Iterable<BigDecimal>): BigDecimal => {
  let out: BigDecimal = one
  for (const n of collection) {
    if (n.value === bigint0) {
      return zero
    }
    out = multiply(out, n)
  }
  return out
}