<N extends Newtype.Any>(
order: Order.Order<Newtype.Carrier<N>>
): Order.Order<N>Lifts an Order for the carrier type into an Order for the newtype.
When to use
Use when you need to sort newtype-wrapped values according to the ordering of the wrapped carrier value, without manually unwrapping.
Details
The returned order delegates to the provided carrier order.
Example (Ordering newtypes)
import { Newtype, Order } from "effect"
interface Score extends Newtype.Newtype<"Score", number> {}
const ord = Newtype.makeOrder<Score>(Order.Number)
const iso = Newtype.makeIso<Score>()
ord(iso.set(1), iso.set(2)) // -1export const const makeOrder: <N extends Newtype.Any>(
order: Order.Order<Newtype.Carrier<N>>
) => Order.Order<N>
Lifts an Order for the carrier type into an Order for the newtype.
When to use
Use when you need to sort newtype-wrapped values according to the ordering
of the wrapped carrier value, without manually unwrapping.
Details
The returned order delegates to the provided carrier order.
Example (Ordering newtypes)
import { Newtype, Order } from "effect"
interface Score extends Newtype.Newtype<"Score", number> {}
const ord = Newtype.makeOrder<Score>(Order.Number)
const iso = Newtype.makeIso<Score>()
ord(iso.set(1), iso.set(2)) // -1
makeOrder: <function (type parameter) N in <N extends Newtype.Any>(order: Order.Order<Newtype.Carrier<N>>): Order.Order<N>N extends Newtype.type Newtype<in out Key extends string, out Carrier>.Any = Newtype<any, unknown>A type that matches any Newtype, useful as a generic constraint:
<N extends Newtype.Any>.
When to use
Use as a generic constraint when a type parameter can be any Newtype.
Any>(order: Order.Order<Newtype.Carrier<N>>order: 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<Newtype.type Newtype<in out Key extends string, out Carrier>.Carrier<N extends Newtype.Any> = N extends Newtype<infer _Key extends string, infer Carrier> ? Carrier : neverExtracts the carrier (underlying) type from a newtype.
When to use
Use when you need to refer to the wrapped type in generic utilities.
Carrier<function (type parameter) N in <N extends Newtype.Any>(order: Order.Order<Newtype.Carrier<N>>): Order.Order<N>N>>) => 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) N in <N extends Newtype.Any>(order: Order.Order<Newtype.Carrier<N>>): Order.Order<N>N> = import castcast