(options: { minimum: bigint; maximum: bigint }): (self: bigint) => bigint
(self: bigint, options: { minimum: bigint; maximum: bigint }): bigintRestricts 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)export const const clamp: {
(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)
clamp: {
(options: {
minimum: bigint
maximum: bigint
}
options: {
minimum: bigintminimum: bigint
maximum: bigintmaximum: bigint
}): (self: bigintself: bigint) => bigint
(self: bigintself: bigint, options: {
minimum: bigint
maximum: bigint
}
options: {
minimum: bigintminimum: bigint
maximum: bigintmaximum: bigint
}): bigint
} = import orderorder.const clamp: <A>(O: Order<A>) => {
(options: { minimum: A; maximum: A }): (
self: A
) => A
(
self: A,
options: { minimum: A; maximum: A }
): A
}
Restricts a value between a minimum and a maximum according to the given order.
When to use
Use when you need to clamp a value to an inclusive range according to an
Order.
Details
Returns the value itself when it is between minimum and maximum, inclusive.
Values below the range return minimum, and values above the range return
maximum. The minimum must be less than or equal to the maximum according to
the order.
Example (Clamping values)
import { Order } from "effect"
const clamp = Order.clamp(Order.Number)({ minimum: 1, maximum: 5 })
console.log(clamp(3)) // 3
console.log(clamp(0)) // 1
console.log(clamp(6)) // 5
clamp(const Order: order.Order<bigint>Provides an Order instance for bigint that allows comparing and sorting BigInt values.
When to use
Use when you need to sort or compare bigint values through APIs that accept
an ordering instance.
Example (Comparing bigints with Order)
import { BigInt } from "effect"
const a = 123n
const b = 456n
const c = 123n
console.log(BigInt.Order(a, b)) // -1 (a < b)
console.log(BigInt.Order(b, a)) // 1 (b > a)
console.log(BigInt.Order(a, c)) // 0 (a === c)
Order)