<const R extends { readonly [x: string]: order.Order<any> }>(
fields: R
): order.Order<{
[K in keyof R]: [R[K]] extends [order.Order<infer A>] ? A : never
}>Creates an Order for a struct by providing an Order for each property.
Properties are compared in the order they appear in the fields object; the
first non-zero comparison determines the result.
When to use
Use when you need to sort record-like objects lexicographically by several fields, with each field using its own ordering rule.
Details
This is an alias of Order.Struct. The order of keys in the fields object
determines comparison priority.
Example (Ordering structs by name then age)
import { Number, String, Struct } from "effect"
const PersonOrder = Struct.makeOrder({
name: String.Order,
age: Number.Order
})
console.log(PersonOrder({ name: "Alice", age: 30 }, { name: "Bob", age: 25 }))
// -1 (Alice comes before Bob)export const const makeOrder: <
R extends { readonly [x: string]: Order<any> }
>(
fields: R
) => Order<{
[K in keyof R]: [R[K]] extends [Order<infer A>]
? A
: never
}>
Creates an Order for a struct by providing an Order for each property.
Properties are compared in the order they appear in the fields object; the
first non-zero comparison determines the result.
When to use
Use when you need to sort record-like objects lexicographically by several
fields, with each field using its own ordering rule.
Details
This is an alias of Order.Struct. The order of keys in the fields object
determines comparison priority.
Example (Ordering structs by name then age)
import { Number, String, Struct } from "effect"
const PersonOrder = Struct.makeOrder({
name: String.Order,
age: Number.Order
})
console.log(PersonOrder({ name: "Alice", age: 30 }, { name: "Bob", age: 25 }))
// -1 (Alice comes before Bob)
makeOrder = import orderorder.function Struct<
R extends { readonly [x: string]: Order<any> }
>(
fields: R
): Order<{
[K in keyof R]: [R[K]] extends [Order<infer A>]
? A
: never
}>
Creates an Order for structs by applying the given Orders to each property in sequence.
When to use
Use when you need multi-field ordering for objects with known properties.
Details
Compares structs field-by-field in the key order of the fields object and
stops at the first non-zero comparison result. Field order matters: earlier
fields take precedence. The result is 0 only if all fields are equal.
Example (Ordering structs)
import { Order } from "effect"
const personOrder = Order.Struct({
name: Order.String,
age: Order.Number
})
const person1 = { name: "Alice", age: 30 }
const person2 = { name: "Bob", age: 25 }
const person3 = { name: "Alice", age: 25 }
console.log(personOrder(person1, person2)) // -1 (Alice < Bob)
console.log(personOrder(person1, person3)) // 1 (same name, 30 > 25)
console.log(personOrder(person1, person1)) // 0
Struct