Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface RangeSpec<T>

An interface representing the knowledge required to create ranges of arbitrary type T.

This interface is required to construct ranges over custom user-provided types. Range uses NumberSpec by default, so there's no need to specify this spec for number-compatible types, e.g. ones that have valueOf(): number implemented.

See Range and RangeSet constructor methods for examples of how this spec is used.

It is recommended to extend AbstractRangeSpec for user-defined ranges.

Type parameters

  • T

    The type the target range contains.

Hierarchy

  • RangeSpec

Implemented by

Index

Properties

comparator

comparator: (a: T, b: T) => number

A standard comparator.

It's expected to return 0 upon equality, a negative number if a < b, and a positive if a > b.

Care needs to be taken around handling infinity cases, since arithmetic operations on Infinity always return NaN, thus potentially breaking this interface. It is thus recommended to handle equality cases separately by returning an explicit 0.

Type declaration

    • (a: T, b: T): number
    • Parameters

      • a: T
      • b: T

      Returns number

Methods

isEqual

  • isEqual(a: T, b: T): boolean

isGreaterOrEqualTo

  • isGreaterOrEqualTo(value: T, thanTo: T): boolean

isGreaterThan

  • isGreaterThan(value: T, than: T): boolean

isInfinity

  • isInfinity(value: T): boolean
  • Should return true for both positive and negative infinity.

    It is possible to have less than two infinities, i.e. it's theoretically possible (albeit not totally practical) to build a range over a field of 0..Infinity, or -Infinity..0.

    Parameters

    • value: T

    Returns boolean

isLessOrEqualTo

  • isLessOrEqualTo(value: T, thanTo: T): boolean

isLessThan

  • isLessThan(value: T, than: T): boolean

Generated using TypeDoc