effect-io-ai

Package: effect
Module: Ordering

Ordering.Ordering

Represents the result of comparing two values.

When to use

Use to model a normalized comparison result that is exactly less than, equal to, or greater than.

Details

Example (Defining comparison results)

import type { Ordering } from "effect"

// Custom comparison function
const compareNumbers = (a: number, b: number): Ordering.Ordering => {
  if (a < b) return -1
  if (a > b) return 1
  return 0
}

console.log(compareNumbers(5, 10)) // -1 (5 < 10)
console.log(compareNumbers(10, 5)) // 1 (10 > 5)
console.log(compareNumbers(5, 5)) // 0 (5 == 5)

// Using with string comparison
const compareStrings = (a: string, b: string): Ordering.Ordering => {
  return a.localeCompare(b) as Ordering.Ordering
}

Signature

type Ordering = -1 | 0 | 1

Source

Since v2.0.0