Skip to main content

Number

Utility functions for Number.

add

Returns the sum of two numbers.

function add(b: number): (a: number) => number
function add(a: number, b: number): number
N.add(10, 20) // → 30
pipe(5, N.add(10)) // → 15

clamp

Clamps a value between an upper and lower bound

function clamp(min: number, max: number): (num: number) => number
function clamp(num: number, min: number, max: number): number
N.clamp(2, 4, 6) // → 4
pipe(10, N.clamp(2, 5)) // → 5

divide

Divides two numbers.

function divide(b: number): (a: number) => number
function divide(a: number, b: number): number
N.divide(20, 5) // → 4
pipe(40, N.divide(4)) // → 10

divideWithModulo

Returns the quotient and remainder of a number division.

function divideWithModulo(b: number): (a: number) => readonly [number, number]
function divideWithModulo(a: number, b: number): readonly [number, number]
N.divideWithModulo(20, 5) // → [4, 0]
pipe(30, N.divideWithModulo(4)) // → [7.5, 2]

gt

Returns true if the first argument is greater than second argument. Otherwise it returns false

function gt(b: number): (a: number) => boolean
function gt(a: number, b: number): boolean
N.gt(2, 4) // → false
pipe(4, N.gt(2)) // → true

gte

Returns true if the first argument is greater or equal than second argument. Otherwise it returns false

function gte(b: number): (a: number) => boolean
function gte(a: number, b: number): boolean
N.gte(2, 4) // → false
pipe(4, N.gte(2)) // → true

lt

Returns true if the first argument is lower than second argument. Otherwise it returns false

function lt(b: number): (a: number) => boolean
function lt(a: number, b: number): boolean
N.lt(2, 4) // → true
pipe(4, N.lt(2)) // → false

lte

Returns true if the first argument is lower or equal than second argument. Otherwise it returns false

function lte(b: number): (a: number) => boolean
function lte(a: number, b: number): boolean
N.lte(2, 4) // → true
pipe(4, N.lte(2)) // → false

modulo

Returns the remainder of a number division.

function modulo(b: number): (a: number) => number
function modulo(a: number, b: number): number
N.modulo(20, 6) // → 2
pipe(30, N.modulo(4)) // → 2

multiply

Multiplies two numbers.

function multiply(b: number): (a: number) => number
function multiply(a: number, b: number): number
N.multiply(3, 6) // → 18
pipe(8, N.multiply(4)) // → 32

pred

Subtracts 1 from the given number.

function pred(n: number): number
N.pred(6) // → 5
pipe(5, N.pred) // → 4

subtract

Returns the difference of two numbers.

function subtract(b: number): (a: number) => number
function subtract(a: number, b: number): number
N.subtract(20, 10) // → 10
pipe(15, N.subtract(10)) // → 5

succ

Adds 1 to the given number.

function succ(n: number): number
N.succ(0) // → 1
A.makeWithIndex(4, N.succ) // → [1, 2, 3, 4]
pipe(5, N.succ) // → 6