Skip to main content

Int

A collection of functions to manipulate integer values

Index

Bound

readonlymaxValue

maxValue: Int

Maximum value for this type

@example
const anyNumber: number
anyNumber < Number.maxValue // true

readonlyminValue

minValue: Int

Minimum value for this type

@example
const anyNumber: number
anyNumber > Number.minValue // true

Codec

codecDecode

  • Returns the decoded input, Result.Ok or Result.Error()

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const input: unknown = ...;
    const decoded = Codec.decode(someCodec, input);

codecEncode

  • codecEncode(this: void, input: Int): unknown
  • Returns the encoded input

    @example
    interface SomeObject {
    foo: string
    }
    const someCodec: Codec<SomeObject> = ...;
    const someObject: SomeObject = { foo: "bar" }
    const encoded = Codec.decode(someCodec, someObject);

codecSchema

  • Returns the JSONSchema corresponding to the decoded type

    @example
    const someCodec: Codec<unknown> = ...;
    const jsonSchema = Codec.schema(someCodec);

Comparator

!=

  • !=(this: void, left: Int, right: Int): boolean
  • "Not equal to" operator

    @example
    const TEqual: Equal<T>;
    TEqual['!='](value, otherValue); // true
    TEqual['!='](value, value); // false

  • (this: void, left: Int, right: Int): boolean
  • "Less than" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['<'](smallerT, smallerT); // false
    TCompare['<'](smallerT, greaterT); // true
    TCompare['<'](greaterT, smallerT); // false

<=

  • <=(this: void, left: Int, right: Int): boolean
  • "Less than or equal to" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['<='](smallerT, smallerT); // true
    TCompare['<='](smallerT, greaterT); // true
    TCompare['<='](greaterT, smallerT); // false

==

  • ==(this: void, left: Int, right: Int): boolean
  • "Equal to" operator

    @example
    type T = // ...
    const TEqual: Equal<T>;
    TEqual['=='](value, value); // true
    TEqual['=='](value, otherValue); // false

  • (this: void, left: Int, right: Int): boolean
  • "Greater than" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['>'](smallerT, smallerT); // false
    TCompare['>'](smallerT, greaterT); // false
    TCompare['>'](greaterT, smallerT); // true

>=

  • >=(this: void, left: Int, right: Int): boolean
  • "Greater than or equal to" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare['>='](smallerT, smallerT); // true
    TCompare['>='](smallerT, greaterT); // false
    TCompare['>='](greaterT, smallerT); // true

clamp

  • clamp(this: void, value: Int, minValue: Int, maxValue: Int): Int
  • Clamp value between minValue and maxValue

    @example
    type T;
    const TCompare: Comparable<T>;
    TCompare.clamp(value, min, max); // min if value < min, max if value > max, otherwise value itself

compare

  • compare(this: void, left: Int, right: Int): number
  • Return a number that represents comparison

    @example
    type T;
    const TCompare: Comparable<T>;
    const sorted = [3, 1, 1].sort(TCompare.compare);

equals

  • equals(this: void, left: Int, right: Int): boolean
  • Alias to '=='

    @example
    type T = // ...
    const TEqual: Equal<T>;
    TEqual.equals(value, value); // true
    TEqual.equals(value, otherValue); // false

max

  • max(this: void, left: Int, right: Int): Int
  • "maximum" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare.max(smallerT, greaterT); // greaterT

min

  • min(this: void, left: Int, right: Int): Int
  • "minimum" operator

    @example
    type T;
    const TCompare: Comparable<T>;
    const smallerT: T;
    const greaterT: T;
    TCompare.min(smallerT, greaterT); // smallerT

Constructor

asInstance

  • asInstance(anyValue: unknown): Option<Int>
  • Try to convert anyValue to enum value or else returns Option.None

    @example
    const StringType: Type<string>;
    StringType.asInstance('foo'); // Option.Some('foo')
    StringType.asInstance(12); // Option.None

fromNumber

  • Return a new integer from value

    @example
    const intValue = Int.fromNumber(0.5);// 0

Numeric

*?

  • *?(base: Int, multiplier: Int): Option<Int>
  • Multiplication operator that returns None instead of wrapping around on overflow.

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedMultiply<T> = ...;
    const result = Numeric['*?'](left, right);// represents (left * right)

+?

  • +?(left: Int, right: Int): Option<Int>
  • Addition operator that returns None instead of wrapping around on overflow.

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedAdd<T> = ...;
    const result = TNumeric['+?'](left, right);// represents (left + right)

-?

  • -?(left: Int, right: Int): Option<Int>
  • Subtraction operator that returns None instead of wrapping around on overflow.

    @example
    type T = ...;
    const TNumeric: Numeric.CheckedSubtract<T> = ...;
    const result = TNumeric['-?'](left, right);// represents (left + right)

abs

  • abs(value: Int): Int
  • Absolute value. It should satisfy Numeric['*'](Numeric.abs(x), Numeric.sign(x)) == x

    @example
    type T = ...;
    const TSigned: Numeric.Signed<T> = ...;
    const result = TSigned.abs(value);// absolute value of (value)

sign

  • sign(value: Int): Int
  • Sign of a number. It should satisfy TSigned['*'](TSigned.abs(x), TSigned.sign(x)) == x

Type

inspect

inspect: Option<(anyValue: Int, depth: number, options: InspectOptions, inspect: InspectFunction) => string>

When defined, returns a custom string representation

@example

@param

hasInstance

  • hasInstance(anyValue: unknown): anyValue is Int
  • Return true if the given value is an instance of the class.

    @example
    const StringType: Type<string>;
    StringType.hasInstance('foo'); // true
    StringType.hasInstance(42); // false

Other

typeName

Re-exports typeName

indexType

indexType: number

Index type

__call__

  • __call__(value: number): Int

at

  • Returns the value at the index

format

  • format(intValue: Int, radix?: Radix36): string
  • Return string representation of integer

    @example
    Int.format(Int(1), 10);// '1'
    Int.format(Int(10), 16);// 'A'

indexOf

  • indexOf(value: Int): Option<Int>
  • Returns the integer index of a value

parse

  • parse(expression: string, radix?: Radix36): Option<Int>
  • Parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems). If the expression is not valid, it returns Option.None

    @example
    Int.parse('1');// Option.Some(1)
    Int.parse('invalid');// Option.None

range

  • range(start: Int, end: Int): Range<Int>
  • Returns an Iterable starting from start to end. If start or end is not in range then returns an empty iterable.

rangeSize

  • rangeSize(start: Int, end: Int): Int
  • Returns the size of a range. If start or end is not in range then returns 0.

unwrap

  • unwrap(value: Int): number
  • Convert a tagged value to the underlying type

wrap

  • wrap(value: number): Int
  • Convert an underlying type to a tagged type