<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)) // 5export const 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 = <function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A>(type O: Order<A>O: interface Order<in A>Represents a total ordering for values of type A.
When to use
Use when you need to define how values of a type are compared.
Details
An order returns -1 when the first value is less than the second, 0 when
the values are equal according to this ordering, and 1 when the first value
is greater than the second. It must satisfy total ordering laws: totality,
antisymmetry, and transitivity.
Example (Defining a custom Order)
import { Order } from "effect"
const byAge: Order.Order<{ name: string; age: number }> = (self, that) => {
if (self.age < that.age) return -1
if (self.age > that.age) return 1
return 0
}
const person1 = { name: "Alice", age: 30 }
const person2 = { name: "Bob", age: 25 }
console.log(byAge(person1, person2)) // 1
Order<function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A>): {
(options: {
minimum: A
maximum: A
}
options: {
minimum: Aminimum: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A
maximum: Amaximum: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A
}): (self: Aself: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A) => function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A
(self: Aself: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A, options: {
minimum: A
maximum: A
}
options: {
minimum: Aminimum: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A
maximum: Amaximum: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A
}): function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A
} =>
import dualdual(
2,
(self: Aself: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A, options: {
minimum: A
maximum: A
}
options: {
minimum: Aminimum: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A
maximum: Amaximum: function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A
}): function (type parameter) A in <A>(O: Order<A>): {
(options: {
minimum: A;
maximum: A;
}): (self: A) => A;
(self: A, options: {
minimum: A;
maximum: A;
}): A;
}
A => const min: <A>(O: Order<A>) => {
(that: A): (self: A) => A
(self: A, that: A): A
}
Returns the minimum of two values according to the given order. If they are equal, returns the first argument.
When to use
Use when you need to select the smaller of two values according to an
Order.
Details
Returns the value that compares as less than or equal to the other value. If
values are equal, the first argument is returned.
Example (Selecting the minimum value)
import { Order } from "effect"
const minNumber = Order.min(Order.Number)
console.log(minNumber(1, 2)) // 1
console.log(minNumber(2, 1)) // 1
console.log(minNumber(1, 1)) // 1
min(type O: Order<A>O)(options: {
minimum: A
maximum: A
}
options.maximum: Amaximum, const max: <A>(O: Order<A>) => {
(that: A): (self: A) => A
(self: A, that: A): A
}
Returns the maximum of two values according to the given order. If they are equal, returns the first argument.
When to use
Use when you need to select the larger of two values according to an
Order.
Details
Returns the value that compares as greater than or equal to the other value.
If values are equal, the first argument is returned.
Example (Selecting the maximum value)
import { Order } from "effect"
const maxNumber = Order.max(Order.Number)
console.log(maxNumber(1, 2)) // 2
console.log(maxNumber(2, 1)) // 2
console.log(maxNumber(1, 1)) // 1
max(type O: Order<A>O)(options: {
minimum: A
maximum: A
}
options.minimum: Aminimum, self: Aself))
)