The exact number of elements.
The input array type (tuple types are preserved).
xs typed as FixedLengthTuple<Length, Xs[number]> & Xs.
const rgb = Arr.asFixedLengthTuple(3, [255, 128, 0]);
const red: number = rgb[0]; // OK — no `undefined`
// curried version
const asRgb = Arr.asFixedLengthTuple(3);
assert.strictEqual(red, 255);
assert.deepStrictEqual(asRgb([0, 255, 0]), [0, 255, 0]);
assert.throws(() => Arr.asFixedLengthTuple(3, [255, 128]), TypeError);
Casts an array to FixedLengthTuple<Length, E> after checking that it has
exactly length elements.
This is the structural counterpart of asFixedLengthArray: it produces a
tuple type rather than the branded FixedLengthArray. Prefer the branded
one unless you specifically need the structural type — the brand keeps
type-checking cost independent of the element type and of the bound.
The length argument comes first, matching the type-parameter order of
FixedLengthTuple<Length, Elm>. Omitting the array returns a function that
casts one.
The exact number of elements.
The exact number of elements.
xs typed as FixedLengthTuple<Length, Xs[number]> & Xs.
const rgb = Arr.asFixedLengthTuple(3, [255, 128, 0]);
const red: number = rgb[0]; // OK — no `undefined`
// curried version
const asRgb = Arr.asFixedLengthTuple(3);
assert.strictEqual(red, 255);
assert.deepStrictEqual(asRgb([0, 255, 0]), [0, 255, 0]);
assert.throws(() => Arr.asFixedLengthTuple(3, [255, 128]), TypeError);
Casts an array to
FixedLengthTuple<Length, E>after checking that it has exactlylengthelements.This is the structural counterpart of
asFixedLengthArray: it produces a tuple type rather than the brandedFixedLengthArray. Prefer the branded one unless you specifically need the structural type — the brand keeps type-checking cost independent of the element type and of the bound.The length argument comes first, matching the type-parameter order of
FixedLengthTuple<Length, Elm>. Omitting the array returns a function that casts one.