(that: bigint): (self: bigint) => bigint
(self: bigint, that: bigint): bigintDivides one bigint by another, throwing if the divisor is zero.
When to use
Use to divide bigint values where the divisor is known to be non-zero and
division by zero should be a thrown exception.
Details
Uses JavaScript bigint division, so non-exact quotients are truncated
toward zero.
Gotchas
Throws a RangeError when the divisor is 0n.
Example (Dividing bigints unsafely)
import { BigInt } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigInt.divideUnsafe(6n, 3n), 2n)
assert.deepStrictEqual(BigInt.divideUnsafe(6n, 4n), 1n)export const const divideUnsafe: {
(that: bigint): (self: bigint) => bigint
(self: bigint, that: bigint): bigint
}
Divides one bigint by another, throwing if the divisor is zero.
When to use
Use to divide bigint values where the divisor is known to be non-zero and
division by zero should be a thrown exception.
Details
Uses JavaScript bigint division, so non-exact quotients are truncated
toward zero.
Gotchas
Throws a RangeError when the divisor is 0n.
Example (Dividing bigints unsafely)
import { BigInt } from "effect"
import * as assert from "node:assert"
assert.deepStrictEqual(BigInt.divideUnsafe(6n, 3n), 2n)
assert.deepStrictEqual(BigInt.divideUnsafe(6n, 4n), 1n)
divideUnsafe: {
(that: bigintthat: bigint): (self: bigintself: bigint) => bigint
(self: bigintself: bigint, that: bigintthat: bigint): bigint
} = dual<(...args: Array<any>) => any, (self: bigint, that: bigint) => bigint>(arity: 2, body: (self: bigint, that: bigint) => bigint): ((...args: Array<any>) => any) & ((self: bigint, that: bigint) => bigint) (+1 overload)Creates a function that can be called in data-first style or data-last
(pipe-friendly) style.
When to use
Use to expose one implementation through both direct and pipe-friendly
call styles.
Details
Pass either the arity of the uncurried function or a predicate that decides
whether the current call is data-first. Arity is the common case. Use a
predicate when optional arguments make arity ambiguous.
Example (Selecting data-first or data-last style by arity)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(2, (self, that) => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Defining overloads with call signatures)
import { Function, pipe } from "effect"
const sum: {
(that: number): (self: number) => number
(self: number, that: number): number
} = Function.dual(2, (self: number, that: number): number => self + that)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
Example (Selecting data-first or data-last style with a predicate)
import { Function, pipe } from "effect"
const sum = Function.dual<
(that: number) => (self: number) => number,
(self: number, that: number) => number
>(
(args) => args.length === 2,
(self, that) => self + that
)
console.log(sum(2, 3)) // 5
console.log(pipe(2, sum(3))) // 5
dual(2, (self: bigintself: bigint, that: bigintthat: bigint): bigint => self: bigintself / that: bigintthat)