diff options
author | Julian Schurhammer <julian.schurhammer@gmail.com> | 2022-08-12 00:04:53 +1200 |
---|---|---|
committer | Louis Pilfold <louis@lpil.uk> | 2023-03-13 10:48:28 +0000 |
commit | cb4cac3c2b5070f3dff423132e3cf20858e82355 (patch) | |
tree | 4b1653ec78402eb26604ad0673b25be2c4172ee5 /src | |
parent | 240db63ea29f10810c4b55b1a9674e4aa8283d05 (diff) | |
download | gleam_stdlib-cb4cac3c2b5070f3dff423132e3cf20858e82355.tar.gz gleam_stdlib-cb4cac3c2b5070f3dff423132e3cf20858e82355.zip |
implement equals for maps in javascript
Diffstat (limited to 'src')
-rw-r--r-- | src/persistent-hash-map.mjs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/persistent-hash-map.mjs b/src/persistent-hash-map.mjs index c2a792c..1851258 100644 --- a/src/persistent-hash-map.mjs +++ b/src/persistent-hash-map.mjs @@ -588,6 +588,7 @@ function forEach(root, fn) { } /** Extra wrapper to keep track of map size */ export class PMap { + static NOT_FOUND = Symbol(); constructor(root, size) { this.root = root; this.size = size; @@ -599,6 +600,13 @@ export class PMap { }); return h; } + equals(o) { + let equal = true; + forEach(this, (v, k) => { + equal = equal && isEqual(v, getWithDefault(o, k, PMap.NOT_FOUND)); + }); + return equal; + } } export function create() { return new PMap(undefined, 0); |