Overview

The Ord type class represents types which support comparisons with a total order.

Instances should satisfy the laws of total orderings:

  1. Reflexivity: S.compare(a, a) <= 0
  2. Antisymmetry: if S.compare(a, b) <= 0 and S.compare(b, a) <= 0 then a <-> b
  3. Transitivity: if S.compare(a, b) <= 0 and S.compare(b, c) <= 0 then S.compare(a, c) <= 0

See Getting started with fp-ts: Ord


Table of contents


Ord (interface)

Signature

export interface Ord<A> extends Eq<A> {
  readonly compare: (x: A, y: A) => Ordering
}

Added in v2.0.0

URI (type alias)

Signature

export type URI = typeof URI

Added in v2.0.0

URI (constant)

Signature

export const URI: "Ord" = ...

Added in v2.0.0

ord (constant)

Signature

export const ord: Contravariant1<URI> = ...

Added in v2.0.0

ordBoolean (constant)

Signature

export const ordBoolean: Ord<boolean> = ...

Added in v2.0.0

ordDate (constant)

Signature

export const ordDate: Ord<Date> = ...

Added in v2.0.0

ordNumber (constant)

Signature

export const ordNumber: Ord<number> = ...

Added in v2.0.0

ordString (constant)

Signature

export const ordString: Ord<string> = ...

Added in v2.0.0

between (function)

Test whether a value is between a minimum and a maximum (inclusive)

Signature

export function between<A>(O: Ord<A>): (low: A, hi: A) => (x: A) => boolean { ... }

Added in v2.0.0

clamp (function)

Clamp a value between a minimum and a maximum

Signature

export function clamp<A>(O: Ord<A>): (low: A, hi: A) => (x: A) => A { ... }

Added in v2.0.0

fromCompare (function)

Signature

export function fromCompare<A>(compare: (x: A, y: A) => Ordering): Ord<A> { ... }

Added in v2.0.0

geq (function)

Test whether one value is non-strictly greater than another

Signature

export function geq<A>(O: Ord<A>): (x: A, y: A) => boolean { ... }

Added in v2.0.0

getDualOrd (function)

Signature

export function getDualOrd<A>(O: Ord<A>): Ord<A> { ... }

Added in v2.0.0

getSemigroup (function)

Signature

export function getSemigroup<A = never>(): Semigroup<Ord<A>> { ... }

Added in v2.0.0

getTupleOrd (function)

Given a tuple of Ords returns an Ord for the tuple

Signature

export function getTupleOrd<T extends Array<Ord<any>>>(
  ...ords: T
): Ord<{ [K in keyof T]: T[K] extends Ord<infer A> ? A : never }> { ... }

Example

import { getTupleOrd, ordString, ordNumber, ordBoolean } from 'fp-ts/lib/Ord'

const O = getTupleOrd(ordString, ordNumber, ordBoolean)
assert.strictEqual(O.compare(['a', 1, true], ['b', 2, true]), -1)
assert.strictEqual(O.compare(['a', 1, true], ['a', 2, true]), -1)
assert.strictEqual(O.compare(['a', 1, true], ['a', 1, false]), 1)

Added in v2.0.0

gt (function)

Test whether one value is strictly greater than another

Signature

export function gt<A>(O: Ord<A>): (x: A, y: A) => boolean { ... }

Added in v2.0.0

leq (function)

Test whether one value is non-strictly less than another

Signature

export function leq<A>(O: Ord<A>): (x: A, y: A) => boolean { ... }

Added in v2.0.0

lt (function)

Test whether one value is strictly less than another

Signature

export function lt<A>(O: Ord<A>): (x: A, y: A) => boolean { ... }

Added in v2.0.0

max (function)

Take the maximum of two values. If they are considered equal, the first argument is chosen

Signature

export function max<A>(O: Ord<A>): (x: A, y: A) => A { ... }

Added in v2.0.0

min (function)

Take the minimum of two values. If they are considered equal, the first argument is chosen

Signature

export function min<A>(O: Ord<A>): (x: A, y: A) => A { ... }

Added in v2.0.0

contramap (export)

Signature

<A, B>(f: (b: B) => A) => (fa: Ord<A>) => Ord<B>

Added in v2.0.0