(self: string, that: string): Ordering.OrderingProvides an Order instance for comparing strings using lexicographic
ordering.
Example (Comparing strings lexicographically)
import { String } from "effect"
console.log(String.Order("apple", "banana")) // -1
console.log(String.Order("banana", "apple")) // 1
console.log(String.Order("apple", "apple")) // 0export const const Order: order.Order<string>Provides an Order instance for comparing strings using lexicographic
ordering.
Example (Comparing strings lexicographically)
import { String } from "effect"
console.log(String.Order("apple", "banana")) // -1
console.log(String.Order("banana", "apple")) // 1
console.log(String.Order("apple", "apple")) // 0
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<string> = import orderorder.const String: Order<string>Order instance for strings that compares them lexicographically using JavaScript's < operator.
When to use
Use when you need lexicographic string ordering.
Details
Uses lexicographic dictionary ordering. The empty string is less than any
non-empty string, and comparisons are case-sensitive.
Example (Ordering strings)
import { Order } from "effect"
console.log(Order.String("apple", "banana")) // -1
console.log(Order.String("banana", "apple")) // 1
console.log(Order.String("apple", "apple")) // 0
String