<A>(O: Order.Order<A>): Order.Order<ReadonlyArray<A>>Creates an Order for arrays based on an element Order. Arrays are
compared element-wise; if all compared elements are equal, shorter arrays
come first.
Example (Comparing arrays)
import { Array, Order } from "effect"
const arrayOrder = Array.makeOrder(Order.Number)
console.log(arrayOrder([1, 2], [1, 3])) // -1export const const makeOrder: <A>(
O: Order.Order<A>
) => Order.Order<ReadonlyArray<A>>
Creates an Order for arrays based on an element Order. Arrays are
compared element-wise; if all compared elements are equal, shorter arrays
come first.
Example (Comparing arrays)
import { Array, Order } from "effect"
const arrayOrder = Array.makeOrder(Order.Number)
console.log(arrayOrder([1, 2], [1, 3])) // -1
makeOrder: <function (type parameter) A in <A>(O: Order.Order<A>): Order.Order<ReadonlyArray<A>>A>(type O: Order.Order<A>O: import OrderOrder.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.Order<A>): Order.Order<ReadonlyArray<A>>A>) => import OrderOrder.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<interface ReadonlyArray<T>ReadonlyArray<function (type parameter) A in <A>(O: Order.Order<A>): Order.Order<ReadonlyArray<A>>A>> = import OrderOrder.function Array<A>(
O: Order<A>
): Order<ReadonlyArray<A>>
Creates an Order for arrays by applying the given Order to each element, then comparing by length if all elements are equal.
When to use
Use when you need lexicographic ordering for arrays of one element type.
Details
Compares arrays element-by-element using the provided order and stops at the
first non-zero comparison result. If all elements are equal, shorter arrays
are less than longer arrays. The result is 0 only if arrays have the same
length and all elements are equal.
Example (Ordering array elements)
import { Order } from "effect"
const arrayOrder = Order.Array(Order.Number)
console.log(arrayOrder([1, 2], [1, 3])) // -1
console.log(arrayOrder([1, 2], [1, 2, 3])) // -1 (shorter array is less)
console.log(arrayOrder([1, 2, 3], [1, 2])) // 1 (longer array is greater)
console.log(arrayOrder([1, 2], [1, 2])) // 0
Array