import { Trie } from "@wry/trie" ; export { Trie as WeakTrie } ; const pool = new Trie < { tuple : Tuple < any > ; } > ( true ) ; export class Tuple < T extends any [ ] > implements ArrayLike < T [ number ] > , Iterable < T [ number ] > { [ i ] : T [ number ] ; public readonly length : number ; public [ Symbol . iterator ] : ( ) => Iterator < T [ number ] > ; public static from < E extends any [ ] > ( ... elements ) { const node = pool . lookupArray ( elements ) ; return node . tuple || ( node . tuple = new Tuple ( elements ) ) ; } public static isTuple ( that ) { return that instanceof Tuple ; } private constructor ( elements ) { this . length = elements . length ; Object . setPrototypeOf ( elements , Tuple . prototype ) ; return Object . freeze ( elements ) ; } } [ Symbol . iterator , ] . forEach ( ( borrowed ) => { const desc = Object . getOwnPropertyDescriptor ( Array . prototype , borrowed ) ; if ( desc ) Object . defineProperty ( Tuple . prototype , borrowed , desc ) ; } ) ; export default Tuple . from ;