@thi.ng/associative
Version:
ES Map/Set-compatible implementations with customizable equality semantics & supporting operations
26 lines (25 loc) • 670 B
JavaScript
import { mixin } from "@thi.ng/api/mixin";
import { map } from "@thi.ng/transducers/map";
const __tostringSet = (x) => [
`${x[Symbol.toStringTag]}(${x.size || 0}) {`,
[...x].map((x2) => __tostring(x2)).join(", "),
"}"
].join(" ");
const __tostringMap = (x) => [
`${x[Symbol.toStringTag]}(${x.size || 0}) {`,
[...map(([k, v]) => `${__tostring(k)} => ${__tostring(v)}`, x)].join(
", "
),
"}"
].join(" ");
const __tostring = (x) => {
return x instanceof Set ? __tostringSet(x) : x instanceof Map ? __tostringMap(x) : JSON.stringify(x);
};
const __tostringMixin = mixin({
toString() {
return __tostring(this);
}
});
export {
__tostringMixin
};