namespace Tuple
A readonly array of fixed length and types.
Companion type: Tuple<T>
Functions
append
Returns the given tuple
with the given values
appended.
append
tuple
with the given values
appended.Definition
function append<T extends
Tuple.Source
, V extends readonly [unknown, ...unknown[]]>(tuple: T, ...values: V): readonly [...T, ...V];
Type parameters
Name | Description |
---|---|
T | |
V |
Parameters
Name | Type | Description |
---|---|---|
tuple | T | the source tuple |
values | V | the values to append |
const t = Tuple.of(1, 'a')
console.log(Tuple.append(t, true, 5))
// => [1, 'a', true, 5]
concat
Returns a Tuple containing the elements of given tuple1
followed by the elements of given tuple2
.
concat
tuple1
followed by the elements of given tuple2
.Definition
function concat<T1 extends
Tuple.Source
, T2 extends
Tuple.Source
>(tuple1: T1, tuple2: T2): readonly [...T1, ...T2];
Type parameters
Name | Description |
---|---|
T1 | |
T2 |
Parameters
Name | Type | Description |
---|---|---|
tuple1 | T1 | the first Tuple |
tuple2 | T2 | the second Tuple |
const t1 = Tuple.of(1, 'a')
const t2 = Tuple.of(true, 5)
console.log(Tuple.concat(t1, t2))
// => [1, 'a', true, 5]
first
Returns the first element of a Tuple.
first
Definition
function first<T extends
Tuple.Source
>(tuple: T): T[0];
Type parameters
Name | Description |
---|---|
T |
Parameters
Name | Type | Description |
---|---|---|
tuple | T | the source tuple |
const t = Tuple.of(1, 'a', true)
console.log(Tuple.first(t))
// => 1
getIndex
Returns the item at the given index
in the givn tuple
.
getIndex
index
in the givn tuple
.Definition
function getIndex<T extends
Tuple.Source
, K extends keyof T = keyof T>(tuple: T, index: K): T[K];
Type parameters
Name | Description |
---|---|
T | |
K |
Parameters
Name | Type | Description |
---|---|---|
tuple | T | the tuple to get the item from |
index | K | the index in of the tuple element |
const t = Tuple.of(1, 'a', true)
console.log(Tuple.getIndex(t, 1))
// => 'a'
init
Returns a Tuple containing all but the last element of the given tuple
.
init
tuple
.last
Returns the last element of a Tuple.
last
of
Convenience method to type Tuple types
of
Definition
function of<T extends
Tuple.NonEmptySource
>(...values: T):
Tuple
<T>;
Type parameters
Name | Description |
---|---|
T |
Parameters
Name | Type | Description |
---|---|---|
values | T | the values of the tuple |
const t = Tuple.of(1, 'a', true)
// type of t => Tuple<[number, string, boolean]>
second
Returns the second element of a Tuple.
second
Definition
function second<T extends
Tuple.Source
>(tuple: T): T[1];
Type parameters
Name | Description |
---|---|
T |
Parameters
Name | Type | Description |
---|---|---|
tuple | T | the source tuple |
const t = Tuple.of(1, 'a', true)
console.log(Tuple.second(t))
// => 'a'
tail
Returns a Tuple containing all but the first element of the given tuple
.
tail
tuple
.updateAt
Returns a copy of the given tuple
where the element at given index
is updated with the given updater
.
updateAt
tuple
where the element at given index
is updated with the given updater
.Definition
function updateAt<T extends
Tuple.Source
, K extends keyof T = keyof T>(tuple: T, index: K, updater:
Update
<T[K]>): T;
Type parameters
Name | Description |
---|---|
T | |
K |
Parameters
Name | Type | Description |
---|---|---|
tuple | T | the source tuple |
index | K | the index in the tuple |
updater | Update <T[K]> | the updater for the value |
const t = Tuple.of(1, 'a', true)
console.log(Tuple.updateAt(t, 1, 'b'))
// => [1, 'b', true]