Skip to main content Link Search Menu Expand Document (external link)

Ordering overview

Added in v2.0.0


Table of contents


combining

combine

Signature

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

Added in v2.0.0

combineAll

Signature

export declare const combineAll: (collection: Iterable<Ordering>) => Ordering

Added in v2.0.0

combineMany

Signature

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

Added in v2.0.0

model

Ordering (type alias)

Signature

export type Ordering = -1 | 0 | 1

Added in v2.0.0

pattern matching

match

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

Signature

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

Example

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")

Added in v2.0.0

utils

reverse

Inverts the ordering of the input Ordering.

Signature

export declare const reverse: (o: Ordering) => Ordering

Example

import { reverse } from "effect/Ordering"

assert.deepStrictEqual(reverse(1), -1)
assert.deepStrictEqual(reverse(-1), 1)
assert.deepStrictEqual(reverse(0), 0)

Added in v2.0.0