Hyperlinkv0.8.0-beta.28

BigInt

BigInt.sumAllconsteffect/BigInt.ts:769
(collection: Iterable<bigint>): bigint

Takes an Iterable of bigints and returns their sum as a single bigint. Returns 0n for an empty iterable.

When to use

Use when you want an immediate aggregate from an iterable instead of a folding reducer owned by another API.

Example (Summing iterable bigints)

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

assert.deepStrictEqual(BigInt.sumAll([2n, 3n, 4n]), 9n)
Source effect/BigInt.ts:7697 lines
export const sumAll = (collection: Iterable<bigint>): bigint => {
  let out = bigint0
  for (const n of collection) {
    out += n
  }
  return out
}