Hyperlinkv0.8.0-beta.28

Struct

Struct.makeOrderconsteffect/Struct.ts:550
<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)
Source effect/Struct.ts:5501 lines
export const makeOrder = order.Struct