<N extends number>(n: N): <T>(
self: ReadonlyArray<T>
) => self is TupleOf<N, T>
<T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>Checks whether a readonly array has exactly n elements.
When to use
Use when you need a Predicate guard for exact tuple length that narrows
ReadonlyArray<T> to TupleOf<N, T>.
Details
This only checks length, not element types, and returns a refinement on the array type.
Example (Checking exact length)
import { Predicate } from "effect"
const isPair = Predicate.isTupleOf(2)
console.log(isPair([1, 2]))export const const isTupleOf: {
<N extends number>(n: N): <T>(
self: ReadonlyArray<T>
) => self is TupleOf<N, T>
<T, N extends number>(
self: ReadonlyArray<T>,
n: N
): self is TupleOf<N, T>
}
Checks whether a readonly array has exactly n elements.
When to use
Use when you need a Predicate guard for exact tuple length that narrows
ReadonlyArray<T> to TupleOf<N, T>.
Details
This only checks length, not element types, and returns a refinement on the
array type.
Example (Checking exact length)
import { Predicate } from "effect"
const isPair = Predicate.isTupleOf(2)
console.log(isPair([1, 2]))
isTupleOf: {
<function (type parameter) N in <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>N extends number>(n: N extends numbern: function (type parameter) N in <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>N): <function (type parameter) T in <T>(self: ReadonlyArray<T>): self is TupleOf<N, T>T>(self: readonly T[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) T in <T>(self: ReadonlyArray<T>): self is TupleOf<N, T>T>) => self: readonly T[]self is type TupleOf<N extends number, T> = N extends N ? number extends N ? T[] : TupleOf_<T, N, []> : neverConstructs a tuple type with exactly N elements of type T.
When to use
Use when you need a fixed-length array type, especially instead of manually
writing [T, T, T, ...] for longer tuples.
Details
- If
N is a literal number, produces a tuple of that exact length.
- If
N is the general number type (non-literal), degrades to Array<T>.
- Negative numbers produce
never.
Example (Checking fixed-length tuples)
import type { Types } from "effect"
// Exactly 3 numbers
const triple: Types.TupleOf<3, number> = [1, 2, 3]
//
TupleOf<function (type parameter) N in <N extends number>(n: N): <T>(self: ReadonlyArray<T>) => self is TupleOf<N, T>N, function (type parameter) T in <T>(self: ReadonlyArray<T>): self is TupleOf<N, T>T>
<function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>T, function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>N extends number>(self: readonly T[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>T>, n: N extends numbern: function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>N): self: readonly T[]self is type TupleOf<N extends number, T> = N extends N ? number extends N ? T[] : TupleOf_<T, N, []> : neverConstructs a tuple type with exactly N elements of type T.
When to use
Use when you need a fixed-length array type, especially instead of manually
writing [T, T, T, ...] for longer tuples.
Details
- If
N is a literal number, produces a tuple of that exact length.
- If
N is the general number type (non-literal), degrades to Array<T>.
- Negative numbers produce
never.
Example (Checking fixed-length tuples)
import type { Types } from "effect"
// Exactly 3 numbers
const triple: Types.TupleOf<3, number> = [1, 2, 3]
//
TupleOf<function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>N, function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>T>
} = import dualdual(2, <function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>T, function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>N extends number>(self: readonly T[]self: interface ReadonlyArray<T>ReadonlyArray<function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>T>, n: N extends numbern: function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>N): self: readonly T[]self is type TupleOf<N extends number, T> = N extends N ? number extends N ? T[] : TupleOf_<T, N, []> : neverConstructs a tuple type with exactly N elements of type T.
When to use
Use when you need a fixed-length array type, especially instead of manually
writing [T, T, T, ...] for longer tuples.
Details
- If
N is a literal number, produces a tuple of that exact length.
- If
N is the general number type (non-literal), degrades to Array<T>.
- Negative numbers produce
never.
Example (Checking fixed-length tuples)
import type { Types } from "effect"
// Exactly 3 numbers
const triple: Types.TupleOf<3, number> = [1, 2, 3]
//
TupleOf<function (type parameter) N in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>N, function (type parameter) T in <T, N extends number>(self: ReadonlyArray<T>, n: N): self is TupleOf<N, T>T> => self: readonly T[]self.ReadonlyArray<T>.length: numberGets the length of the array. This is a number one higher than the highest element defined in an array.
length === n: N extends numbern)