Ƭ T: Object
Represents a numeric range from a starting value start
to an ending value end
.
Name | Type |
---|---|
start |
number |
end |
number |
step |
number |
[iterator] |
() => Iterator <number , any , undefined > |
▸ 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
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 |
▸ 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
Name | Type | Description |
---|---|---|
x |
unknown |
the value to check |
x is T
true if x
is a T
, false otherwise
▸ 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
Name | Type | Description |
---|---|---|
t |
T |
the range |
a |
number |
the value to check |
boolean
▸ 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
Name | Type | Description |
---|---|---|
t |
number |
the value to check |
the unary function Fn.Unary<T, boolean>
▸ 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
Name | Description |
---|---|
A |
the mapped value type |
Name | Type | Description |
---|---|---|
t |
T |
the Range |
m |
Mappable <number , A > |
the Mappable functor |
A
[]
A[] if t
is Range.T
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
Name | Description |
---|---|
A |
the mapped value type |
Name | Type | Description |
---|---|---|
t |
Mappable <number , A > |
the Range |
the unary function
▸ 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
Name |
---|
T |
Name | Type |
---|---|
arrayLike |
ArrayLike <T > |
T
[]
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
Name |
---|
T |
U |
Name | Type |
---|---|
arrayLike |
ArrayLike <T > |
mapfn |
(v : T , k : number ) => U |
thisArg? |
any |
U
[]
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
Name |
---|
T |
Name | Type |
---|---|
iterable |
Iterable <T > | ArrayLike <T > |
T
[]
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
Name |
---|
T |
U |
Name | Type |
---|---|
iterable |
Iterable <T > | ArrayLike <T > |
mapfn |
(v : T , k : number ) => U |
thisArg? |
any |
U
[]
node_modules/typescript/lib/lib.es2015.iterable.d.ts:91