/** * Helper functions that have to do with TypeScript tuples. * * @module */ import type { Tuple } from "../types/Tuple.js"; type TupleKey = { [L in T["length"]]: Exclude>["length"], L>; }[T["length"]]; type TupleValue = T[0]; type TupleEntry = [TupleKey, TupleValue]; // eslint-disable-line perfectionist/sort-modules /** * Helper function to get the entries (i.e., indexes and values) of a tuple in a type-safe way. * * This is useful because the vanilla `Array.entries` method will always have the keys be of type * `number`. */ export function* tupleEntries( tuple: T, ): Generator> { yield* tuple.entries() as Generator>; } /** * Helper function to get the keys (i.e., indexes) of a tuple in a type-safe way. * * This is useful because the vanilla `Array.keys` method will always have the keys be of type * `number`. */ export function* tupleKeys( tuple: T, ): Generator> { yield* tuple.keys() as Generator>; }