Module Relude_Int

Relude.Int contains functions and typeclass instances for the int type.

let toFloat: int => float;

toFloat returns the floating-point representation of the int

let fromFloat: float => int;

fromFloat turns a float into an int by dropping the fractional part.

Floats that can't be represented as an int (e.g. infinity, nan) will return 0.

let zero: int;

The integer value 0

let one: int;

The integer value 1

let add: int => int => int;

Finds the sum of two integers

let subtract: int => int => int;

Finds the difference of two integers

let multiply: int => int => int;

Finds the product of two integers

let divide: int => int => int;

Finds the quotient of an integer division

let modulo: int => int => int;

Finds the remainder of an integer division

let divideWithModulo: int => int => (int, int);

Finds the quotient and remainder of an integer division

let divideAsFloat: int => int => float;

Converts two int values to floats, then performs a float division

let top: int;

The top bound (max value) of 32 bit int

let bottom: int;

The bottom bound (min value) of 32 bit int

let degree: int => int;

Degree finds the smaller of the absolute value of the given in, or the max int value

let rangeAsList: int => int => list(int);

rangeAsList(n, m) returns a list of integers [n, n + 1, .. m - 1].

rangeAsList(10, 15) == [10, 11, 12, 13, 14];
rangeAsList(10, 10) == [];
rangeAsList(15, 10) == [];
let rangeAsArray: int => int => array(int);

rangeAsArray(n, m) returns an array of integers [|n, n + 1, .. m - 1|].

rangeAsArray(10, 15) == [|10, 11, 12, 13, 14|];
rangeAsArray(10, 10) == [||];
rangeAsArray(15, 10) == [||];
let eq: int => int => bool;

eq(a, b) returns true if the arguments are equal, false otherwise.

module Eq: BsBastet.Interface.EQ with type Eq.t = int;
include { ... };
let eqWithConversion: ('b => Eq.t) => Relude_Eq.eq('b);
let notEq: Relude_Eq.eq(Eq.t);
let eqInverted: Relude_Eq.eq(Eq.t);
module EqInverted: { ... };
module type EQ_BY_F = (A: { ... }) => { ... };
module EqBy: (A: { ... }) => { ... };
let compare: int => int => BsBastet.Interface.ordering;

Int.compare returns `less_than if the first int is less than the second, `greater_than if the first is larger than the second, and `equal_to if the two ints are the same.

Int.compare(3, 5) == `less_than;
Int.compare(3, 3) == `equal_to;
Int.compare(5, 3) == `greater_than;
module Ord: BsBastet.Interface.ORD with type Ord.t = int;
include { ... };
let compareWithConversion: ('b => Ord.t) => Relude_Ord.compare('b);
let compareReversed: Relude_Ord.compare(Ord.t);
module OrdReversed: { ... };
let compareAsInt: Ord.t => Ord.t => int;
let min: Ord.t => Ord.t => Ord.t;
let max: Ord.t => Ord.t => Ord.t;
let lessThan: Ord.t => Ord.t => bool;
let lt: Ord.t => Ord.t => bool;
let lessThanOrEq: Ord.t => Ord.t => bool;
let lte: Ord.t => Ord.t => bool;
let greaterThan: Ord.t => Ord.t => bool;
let gt: Ord.t => Ord.t => bool;
let greaterThanOrEq: Ord.t => Ord.t => bool;
let gte: Ord.t => Ord.t => bool;
let clamp: min:Ord.t => max:Ord.t => Ord.t => Ord.t;
let between: min:Ord.t => max:Ord.t => Ord.t => bool;
module OrdRingExtensions: (R: { ... }) => { ... };
module OrdNamed: { ... };
module type ORD_BY_F = (A: { ... }) => { ... };
module OrdBy: (A: { ... }) => { ... };
module Bounded: BsBastet.Interface.BOUNDED with type Bounded.t = int;
include { ... };
module Enum: Relude_Interface.ENUM with type Enum.t = int;
include { ... };
let fromToAsList: start:Enum.t => finish:Enum.t => list(Enum.t);
let upFromAsList: Enum.t => list(Enum.t);
let upFromIncludingAsList: Enum.t => list(Enum.t);
let downFromAsList: Enum.t => list(Enum.t);
let downFromIncludingAsList: Enum.t => list(Enum.t);
module Semiring: BsBastet.Interface.SEMIRING with type Semiring.t = int;
include { ... };
module Ring: BsBastet.Interface.RING with type Ring.t = int;
include { ... };
let (-): Ring.t => Ring.t => Ring.t;
let negate: Ring.t => Ring.t;
include { ... };
let abs: Ring.t => Ring.t;
let signum: Ring.t => Ring.t;
module EuclideanRing: BsBastet.Interface.EUCLIDEAN_RING with type EuclideanRing.t = int;
module Map: { ... };

Map module with an int key

module Set: { ... };

Set module for ints

let show: int => string;

Int.show returns the string representation of the provided int.

Note that because there are multiple ways to represent integer constants in source code, this string representation may not match the exact input to the function.

Int.show(57) == "57";
Int.show(0x1a) == "26";
let toString: int => string;

Int.toString is an alias for show.

module Show: BsBastet.Interface.SHOW with type Show.t = int;
let fromString: string => option(int);

Int.fromString attempts to parse the given string as an integer. If the given string is a valid integer, Some is returned, otherwise None.

Note that unlike parseInt in JavaScript, this won't return "the good part" up until it fails to parse. If any part of the provided string is not a valid int, the whole thing fails to parse and returns None.

Int.fromString("57") == Some(57);
Int.fromString("0x1a") == Some(26);
Int.fromString("57.3") == None;
Int.fromString("3dozen") == None;
module Additive: { ... };
module Multiplicative: { ... };
module Subtractive: { ... };
module Divisive: { ... };
module Infix: { ... };