It doesn’t seem conveniently possible. What can you do? Something horrible, as always.
const tuple = (() => {
const map = new Map();
return (...args) => {
let current = map;
Object.freeze(args);
for (const item of args) {
if (current.has(item)) {
current = current.get(item);
} else {
const next = new Map();
current.set(item, next);
current = next;
}
}
if (!current.final) {
current.final = args;
}
return current.final;
};
})();
And voilà.
let m = new Map();
m.set(tuple(3, 5), [tuple(3, 5, 3), tuple(3, 5, 4)]);
m.get(tuple(3, 5)); // [[3, 5, 3], [3, 5, 4]]
Ry- ♦
- 226.3k
- 56
- 496
- 504