<A>(that: Order<A>): (self: Order<A>) => Order<A>
<A>(self: Order<A>, that: Order<A>): Order<A>Combines two Order instances to create a new Order that first compares using the first Order,
and if the values are equal, then compares using the second Order.
When to use
Use when you need tie-breaking with exactly two orders.
Details
First applies the first order. If the result is non-zero, that result is
returned; otherwise, the second order is applied. The result is the first
non-zero comparison result, or 0 if both orders return 0.
Example (Combining two Orders)
import { Order } from "effect"
const byAge = Order.mapInput(
Order.Number,
(person: { name: string; age: number }) => person.age
)
const byName = Order.mapInput(
Order.String,
(person: { name: string; age: number }) => person.name
)
const byAgeAndName = Order.combine(byAge, byName)
const person1 = { name: "Alice", age: 30 }
const person2 = { name: "Bob", age: 30 }
const person3 = { name: "Charlie", age: 25 }
console.log(byAgeAndName(person1, person2)) // -1 (Same age, Alice < Bob)
console.log(byAgeAndName(person1, person3)) // 1 (Alice (30) > Charlie (25))export const const combine: {
<A>(that: Order<A>): (
self: Order<A>
) => Order<A>
<A>(self: Order<A>, that: Order<A>): Order<A>
}
Combines two Order instances to create a new Order that first compares using the first Order,
and if the values are equal, then compares using the second Order.
When to use
Use when you need tie-breaking with exactly two orders.
Details
First applies the first order. If the result is non-zero, that result is
returned; otherwise, the second order is applied. The result is the first
non-zero comparison result, or 0 if both orders return 0.
Example (Combining two Orders)
import { Order } from "effect"
const byAge = Order.mapInput(
Order.Number,
(person: { name: string; age: number }) => person.age
)
const byName = Order.mapInput(
Order.String,
(person: { name: string; age: number }) => person.name
)
const byAgeAndName = Order.combine(byAge, byName)
const person1 = { name: "Alice", age: 30 }
const person2 = { name: "Bob", age: 30 }
const person3 = { name: "Charlie", age: 25 }
console.log(byAgeAndName(person1, person2)) // -1 (Same age, Alice < Bob)
console.log(byAgeAndName(person1, person3)) // 1 (Alice (30) > Charlie (25))
combine: {
<function (type parameter) A in <A>(that: Order<A>): (self: Order<A>) => Order<A>A>(that: Order<A>that: 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>(that: Order<A>): (self: Order<A>) => Order<A>A>): (self: Order<A>self: 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>(that: Order<A>): (self: Order<A>) => Order<A>A>) => 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>(that: Order<A>): (self: Order<A>) => Order<A>A>
<function (type parameter) A in <A>(self: Order<A>, that: Order<A>): Order<A>A>(self: Order<A>self: 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>(self: Order<A>, that: Order<A>): Order<A>A>, that: Order<A>that: 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>(self: Order<A>, that: Order<A>): Order<A>A>): 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>(self: Order<A>, that: Order<A>): Order<A>A>
} = import dualdual(2, <function (type parameter) A in <A>(self: Order<A>, that: Order<A>): Order<A>A>(self: Order<A>self: 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>(self: Order<A>, that: Order<A>): Order<A>A>, that: Order<A>that: 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>(self: Order<A>, that: Order<A>): Order<A>A>): 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>(self: Order<A>, that: Order<A>): Order<A>A> =>
function make<A>(
compare: (self: A, that: A) => -1 | 0 | 1
): Order<A>
Creates a new Order instance from a comparison function.
When to use
Use when you need a sorting rule not covered by the built-in orders or input
mapping helpers, and you can provide a total comparison.
Details
Uses reference equality (===) as a shortcut: if self === that, it returns
0 without calling the comparison function. The comparison function should
return -1, 0, or 1, and the returned order satisfies total ordering
laws when the comparison function does.
Example (Creating an Order)
import { Order } from "effect"
const byAge = Order.make<{ name: string; age: number }>((self, that) => {
if (self.age < that.age) return -1
if (self.age > that.age) return 1
return 0
})
console.log(byAge({ name: "Alice", age: 30 }, { name: "Bob", age: 25 })) // 1
console.log(byAge({ name: "Alice", age: 25 }, { name: "Bob", age: 30 })) // -1
make((a1: Aa1, a2: Aa2) => {
const const out: Orderingout = self: Order<A>self(a1: Aa1, a2: Aa2)
if (const out: Orderingout !== 0) {
return const out: 1 | -1out
}
return that: Order<A>that(a1: Aa1, a2: Aa2)
}))