tiinvo

tiinvo / Exports / Range

Namespace: Range

Table of contents

Type Aliases

Factories

Guardables

Predicates

Mappables

Serializables

Type Aliases

T

Ƭ T: Object

Represents a numeric range from a starting value start to an ending value end.

Type declaration

Name Type
start number
end number
step number
[iterator] () => Iterator<number, any, undefined>

Defined in

src/Range.ts:7

Factories

make

make(start, end, step?): T

Makes a new range from a start to an end (inclusive)

If the third parameter step is passed, the range will increment by that step

Important: the range accepts negative values, and the end does not have to be greater than the start.

Example

import { Range } from 'tiinvo'

for (const n of Range.make(0, 10)) {
   console.log(n)
}

// will log 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

for (const n of Range.make(0, 10, 2)) {
   console.log(n)
}

// will log 0, 2, 4, 6, 8, 10

for (const n of Range.make(10, 0, 2)) {
   console.log(n)
}

// will log 10, 8, 6, 4, 2, 0

Since

4.0.0

Parameters

Name Type Default value Description
start number undefined range’s starting value
end number undefined range’s ending value
step number 1 range’s increment value

Returns

T

Defined in

src/Range.ts:53

Guardables

guard

guard(x): x is T

Checks if a parameter x is of Range.T type

Example

import { Range } from 'tiinvo'

Range.guard(10)                                // false
Range.guard([])                                // false
Range.guard({})                                // false
Range.guard({ start: 10, end: 20 })            // false
Range.guard({ start: 10, end: 20, step: 12 })  // false
Range.guard(Range.make(1, 2))                  // true

Since

4.0.0

Parameters

Name Type Description
x unknown the value to check

Returns

x is T

true if x is a T, false otherwise

Defined in

src/Range.ts:111

Predicates

inRange

inRange(t, a): boolean

Checks whenever a number is within in a Range.T

Example

import { Range } from 'tiinvo'

const r = Range.make(3, 8)

Range.inRange(r, 10)   // false
Range.inRange(r, 6)    // true

Since

4.0.0

Parameters

Name Type Description
t T the range
a number the value to check

Returns

boolean

Defined in

src/Range.ts:136

inRange(t): Unary<T, boolean>

Returns a unary function which checks whenever a Range.T contains a value t

Example

import { Range } from 'tiinvo'

const r = Range.make(3, 8)

Range.inRange(10)(r)   // false
Range.inRange(6)(r)    // true

Since

4.0.0

Parameters

Name Type Description
t number the value to check

Returns

Unary<T, boolean>

the unary function Fn.Unary<T, boolean>

Defined in

src/Range.ts:156

Mappables

map

map<A>(t, m): A[]

Maps a functor Mappable<number, A> over a Range.T

Example

import { Range, Num } from 'tiinvo'

const r = Range.make(20, 30)

Range.map(r, Num.toHex)   // ['0x14', '0x15', '0x16', '0x17', '0x18', '0x19', '0x1a', '0x1b', '0x1c', '0x1d', '0x1e']

Since

4.0.0

Type parameters

Name Description
A the mapped value type

Parameters

Name Type Description
t T the Range
m Mappable<number, A> the Mappable functor

Returns

A[]

A[] if t is Range.T

Defined in

src/Range.ts:196

map<A>(t): Unary<T, A[]>

Returns a unary function which maps a functor Mappable<number, A> over a Range.T

Example

import { Range, Num } from 'tiinvo'

const r = Range.make(20, 30)
const m = Range.map(Num.toHex)

m(r)   // ['0x14', '0x15', '0x16', '0x17', '0x18', '0x19', '0x1a', '0x1b', '0x1c', '0x1d', '0x1e']

Since

4.0.0

Type parameters

Name Description
A the mapped value type

Parameters

Name Type Description
t Mappable<number, A> the Range

Returns

Unary<T, A[]>

the unary function

Defined in

src/Range.ts:217

Serializables

toArray

toArray<T>(arrayLike): T[]

Converts a Range.T to a number[] array

Example

import { Range } from 'tiinvo'

const r = Range.make(0, 10)

Range.toArray(r)   // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Since

4.0.0

Type parameters

Name
T

Parameters

Name Type
arrayLike ArrayLike<T>

Returns

T[]

Defined in

node_modules/typescript/lib/lib.es2015.core.d.ts:72

toArray<T, U>(arrayLike, mapfn, thisArg?): U[]

Converts a Range.T to a number[] array

Example

import { Range } from 'tiinvo'

const r = Range.make(0, 10)

Range.toArray(r)   // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Since

4.0.0

Type parameters

Name
T
U

Parameters

Name Type
arrayLike ArrayLike<T>
mapfn (v: T, k: number) => U
thisArg? any

Returns

U[]

Defined in

node_modules/typescript/lib/lib.es2015.core.d.ts:80

toArray<T>(iterable): T[]

Converts a Range.T to a number[] array

Example

import { Range } from 'tiinvo'

const r = Range.make(0, 10)

Range.toArray(r)   // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Since

4.0.0

Type parameters

Name
T

Parameters

Name Type
iterable Iterable<T> | ArrayLike<T>

Returns

T[]

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:83

toArray<T, U>(iterable, mapfn, thisArg?): U[]

Converts a Range.T to a number[] array

Example

import { Range } from 'tiinvo'

const r = Range.make(0, 10)

Range.toArray(r)   // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Since

4.0.0

Type parameters

Name
T
U

Parameters

Name Type
iterable Iterable<T> | ArrayLike<T>
mapfn (v: T, k: number) => U
thisArg? any

Returns

U[]

Defined in

node_modules/typescript/lib/lib.es2015.iterable.d.ts:91