effect-io-ai

Package: effect
Module: Order

Order.Tuple

Creates an Order for a tuple type based on orders for each element.

When to use

Use when you need fixed-length tuple ordering with per-position orders.

Details

Compares tuples element-by-element using the corresponding order and stops at the first non-zero comparison result. Tuples must have the same length as the order collection, and the result is 0 only if all elements are equal.

Example (Ordering tuples)

import { Order } from "effect"

const tupleOrder = Order.Tuple([Order.Number, Order.String])

console.log(tupleOrder([1, "a"], [2, "b"])) // -1
console.log(tupleOrder([1, "b"], [1, "a"])) // 1
console.log(tupleOrder([1, "a"], [1, "a"])) // 0

See

Signature

declare const Tuple: <const Elements extends ReadonlyArray<Order<any>>>(elements: Elements) => Order<{ readonly [I in keyof Elements]: [Elements[I]] extends [Order<infer A>] ? A : never; }>

Source

Since v4.0.0