Module Relude_Int
Relude.Int
contains functions and typeclass instances for the int
type.
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 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 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) == [||];
module Eq: BsBastet.Interface.EQ with type Eq.t = int;
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 Bounded: BsBastet.Interface.BOUNDED with type Bounded.t = int;
include { ... };
module Enum: Relude_Interface.ENUM with type Enum.t = int;
module Semiring: BsBastet.Interface.SEMIRING with type Semiring.t = int;
include { ... };
module Ring: BsBastet.Interface.RING with type Ring.t = int;
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 forshow
.
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, otherwiseNone
.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 validint
, the whole thing fails to parse and returnsNone
.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: { ... };