Ƭ T<A
>: A
Describes a tuple type.
Example
import type { T } from 'tiinvo/Tuple'
type SomeTuple = T<[0 | 1, string, 'foo' | 'bar']>
let a: SomeTuple = [0, 'hello', 'foo']
let b: SomeTuple = [1, 'hello', 'bar']
let c: SomeTuple = [2, 'hello', 'baz'] // wrong type
Since
4.0.0
Name | Type | Description |
---|---|---|
A |
extends any [] |
the tuple data content type |
▸ guardOf<A
>(a
, x
): x is GuardArrayReturnType<A>
Guards if x
is a tuple T
which satisfies guards A
Example
import { Tuple, Str, Num } from 'tiinvo'
Tuple.guardOf([Str, Num], ["hello"]) // false
Tuple.guardOf([Str, Num], ["hello", 100]) // true
Tuple.guardOf([Str, Num], ["hello", "world"]) // false
Tuple.guardOf([Str, Num], ["hello", 100, 100]) // false
Since
4.0.0
Name | Type |
---|---|
A |
extends (Guardable <any > | GuardableModule <any >)[] |
Name | Type |
---|---|
a |
A |
x |
unknown |
x is GuardArrayReturnType<A>
▸ guardOf<A
>(a
): (x
: unknown
) => x is T<GuardArrayReturnType<A>>
Returns a Guardable from a tuple of guards A
Example
import { Tuple, Str, Num } from 'tiinvo'
const guard = Tuple.guardOf([Str, Num])
guard(["hello"]) // false
guard(["hello", 100]) // true
guard(["hello", "world"]) // false
guard(["hello", 100, 100]) // false
Since
4.0.0
Name | Type |
---|---|
A |
extends (Guardable <any > | GuardableModule <any >)[] |
Name | Type |
---|---|
a |
A |
fn
▸ (x
): x is T<GuardArrayReturnType<A>>
Name | Type |
---|---|
x |
unknown |
x is T<GuardArrayReturnType<A>>
▸ get<A
>(tuple
, index
): T
<T
<A
>[typeof index
]>
Gets a value at a specified index, returning it as an Option.T<A[index]>
Example
import { Tuple } from 'tiinvo'
Tuple.get([10, 'hello'], 0) // 10
Tuple.get([10, 'hello'], 1) // "hello"
Tuple.get([10, 'hello'], 2) // null
Since
4.0.0
Name | Type |
---|---|
A |
extends any [] |
Name | Type |
---|---|
tuple |
A |
index |
number |
▸ get(tuple
): <A>(x
: T
<A
>) => T
<T
<A
>[typeof tuple
]>
sets a specified index, returning a unary function which accepts a Tuple.T
Example
import { Tuple } from 'tiinvo'
const t = [10, "hello"]
const get0 = Tuple.get(0);
const get1 = Tuple.get(1);
const get2 = Tuple.get(2);
get0(t) // 10
get1(t) // "hello"
get2(t) // null
Since
4.0.0
Name | Type |
---|---|
tuple |
number |
fn
▸ <A
>(x
): T
<T
<A
>[typeof tuple
]>
Name | Type |
---|---|
A |
extends any [] |
Name | Type |
---|---|
x |
T <A > |
▸ length(a
): number
Returns a Tuple’s length
Example
import { Tuple } from 'tiinvo'
Tuple.length([10, 20, 30]) // 3
Since
4.0.0
Name | Type |
---|---|
a |
any |
number
▸ map<M
, B
>(m
, t
): T
<MappableReturnTypes
<M
>>
Uses a tuple of mappables to map a tuple T<A>
to T<B>
Example
import { Tuple } from 'tiinvo'
const m0 = (x: string) => x.length;
const m1 = (x: Date) => x.getFullYear();
Tuple.map([m0, m1], ["hello", new Date(2022, 1, 2, 3, 4)]) // [5, 2022]
Since
4.0.0
Name | Type | Description |
---|---|---|
M |
extends (Mappable <any , any > | MappableModule <any , any >)[] |
the tuple of Mappables |
B |
extends any [] |
the tuple of values |
Name | Type |
---|---|
m |
M |
t |
B |
T
<MappableReturnTypes
<M
>>
the mapped tuple
▸ map<M
>(m
): <B>(x
: T
<B
>) => T
<MappableReturnTypes
<M
>>
Uses a tuple of mappables to return a Mappable which maps a tuple T<A>
to T<B>
Example
import { Tuple, Str, Num } from 'tiinvo'
const map = Tuple.map([Str.length, Str.charAt(0), Num.gt(0), Num.toHex])
map(["hello", "hello", 10, 10]) // [5, "h", true, "0xa"]
Since
4.0.0
Name | Type | Description |
---|---|---|
M |
extends (Mappable <any , any > | MappableModule <any , any >)[] |
the tuple of Mappables |
Name | Type |
---|---|
m |
M |
fn
the Mappable function
▸ <B
>(x
): T
<MappableReturnTypes
<M
>>
Name | Type |
---|---|
B |
extends any [] |
Name | Type |
---|---|
x |
T <B > |
T
<MappableReturnTypes
<M
>>