Skip to content
Effect Days 2026 Get your ticket

Ordering

6 exports Added in v2.0.0 Source

Combining

combine

Added in v2.0.0 Source

Signature

declare const combine: {
(that: Ordering): (self: Ordering) => Ordering;
(self: Ordering, that: Ordering): Ordering;
}

combineAll

Added in v2.0.0 Source

Signature

declare function combineAll(collection: Iterable<Ordering>): Ordering

combineMany

Added in v2.0.0 Source

Signature

declare const combineMany: {
(collection: Iterable<Ordering>): (self: Ordering) => Ordering;
(self: Ordering, collection: Iterable<Ordering>): Ordering;
}

Model

Ordering type

Added in v2.0.0 Source

Signature

type Ordering = -1 | 0 | 1

Other

reverse

Added in v2.0.0 Source

Inverts the ordering of the input Ordering.

Signature

declare function reverse(o: Ordering): Ordering

Example

import * as assert from "node:assert"
import { reverse } from "effect/Ordering"
assert.deepStrictEqual(reverse(1), -1)
assert.deepStrictEqual(reverse(-1), 1)
assert.deepStrictEqual(reverse(0), 0)

Pattern Matching

match

Added in v2.0.0 Source

Depending on the Ordering parameter given to it, returns a value produced by one of the 3 functions provided as parameters.

Signature

declare const match: {
<A, B, C = B>(options: {
readonly onEqual: LazyArg<B>;
readonly onGreaterThan: LazyArg<C>;
readonly onLessThan: LazyArg<A>;
}): (self: Ordering) => A | B | C;
<A, B, C = B>(o: Ordering, options: {
readonly onEqual: LazyArg<B>;
readonly onGreaterThan: LazyArg<C>;
readonly onLessThan: LazyArg<A>;
}): A | B | C;
}

Example

import * as assert from "node:assert"
import { Ordering } from "effect"
import { constant } from "effect/Function"
const toMessage = Ordering.match({
onLessThan: constant('less than'),
onEqual: constant('equal'),
onGreaterThan: constant('greater than')
})
assert.deepStrictEqual(toMessage(-1), "less than")
assert.deepStrictEqual(toMessage(0), "equal")
assert.deepStrictEqual(toMessage(1), "greater than")