Tuple

Here's a quick and mostly-decent ES6 Tuple type.

class Tuple {

    get arity () {
        return Object.keys(this).length;
    }

    constructor (...params) {
        params.forEach((item, index) => Object.defineProperty(this, index, {
            enumerable: true,
            value: params[index]
        }));
        Object.freeze(this);
    }

    toString () {
        return "[Tuple " + Object.keys(this).map(k => `${k}:${this[k].toString()}`).join(" ") + "]";
    }

}


export default Object.freeze(Tuple);  

No rights reserved.