UNPKG

@thi.ng/associative

Version:

ES Map/Set-compatible implementations with customizable equality semantics & supporting operations

34 lines (33 loc) 573 B
import { equiv } from "@thi.ng/equiv"; const __equivMap = (a, b) => { if (a === b) { return true; } if (!(b instanceof Map) || a.size !== b.size) { return false; } for (let p of a.entries()) { if (!equiv(b.get(p[0]), p[1])) { return false; } } return true; }; const __equivSet = (a, b) => { if (a === b) { return true; } if (!(b instanceof Set) || a.size !== b.size) { return false; } for (let k of a.keys()) { if (!b.has(k)) { return false; } } return true; }; export { __equivMap, __equivSet };