Hyperlinkv0.8.0-beta.28

BigInt

BigInt.clampconsteffect/BigInt.ts:493
(options: { minimum: bigint; maximum: bigint }): (self: bigint) => bigint
(self: bigint, options: { minimum: bigint; maximum: bigint }): bigint

Restricts the given bigint to be within the range specified by the minimum and maximum values.

When to use

Use to force a bigint into an inclusive range.

Details

If the bigint is less than the minimum, the function returns the minimum. If the bigint is greater than the maximum, the function returns the maximum. Otherwise, it returns the original bigint.

Example (Clamping a bigint to bounds)

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

const clamp = BigInt.clamp({ minimum: 1n, maximum: 5n })

assert.equal(clamp(3n), 3n)
assert.equal(clamp(0n), 1n)
assert.equal(clamp(6n), 5n)
Source effect/BigInt.ts:49310 lines
export const clamp: {
  (options: {
    minimum: bigint
    maximum: bigint
  }): (self: bigint) => bigint
  (self: bigint, options: {
    minimum: bigint
    maximum: bigint
  }): bigint
} = order.clamp(Order)