@thi.ng/associative
Version:
ES Map/Set-compatible implementations with customizable equality semantics & supporting operations
20 lines (19 loc) • 420 B
JavaScript
import { copy } from "@thi.ng/object-utils/copy";
import { __combineSet } from "./internal/combine.js";
import { into } from "./into.js";
const union = (a, b, out) => {
if (a.size < b.size) {
const t = a;
a = b;
b = t;
}
out = out ? into(out, a) : copy(a, Set);
return a === b ? out : into(out, b);
};
function unionR(src) {
return __combineSet(unionR, union, src);
}
export {
union,
unionR
};