Hyperlinkv0.8.0-beta.28

BigInt

BigInt.divideconsteffect/BigInt.ts:186
(that: bigint): (self: bigint) => Option.Option<bigint>
(self: bigint, that: bigint): Option.Option<bigint>

Divides one bigint by another safely.

When to use

Use to divide bigint values while representing division by zero as Option.none.

Details

Uses JavaScript bigint division, so non-exact quotients are truncated toward zero. Returns Option.none() when the divisor is 0n.

Example (Dividing bigints safely)

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

assert.deepStrictEqual(BigInt.divide(6n, 3n), Option.some(2n))
assert.deepStrictEqual(BigInt.divide(6n, 0n), Option.none())
Source effect/BigInt.ts:1867 lines
export const divide: {
  (that: bigint): (self: bigint) => Option.Option<bigint>
  (self: bigint, that: bigint): Option.Option<bigint>
} = dual(
  2,
  (self: bigint, that: bigint): Option.Option<bigint> => that === bigint0 ? Option.none() : Option.some(self / that)
)