Skip to content

Commit

Permalink
Add difference method and static
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasjpaterno committed May 6, 2020
1 parent 3096062 commit bee0101
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ export default class MaFP<K, V> extends Map<K, V> {
}
return _difference;
}

static difference<K, V, T extends Map<K, V>>(mapA: T, mapB: T): MaFP<K, V> {
const _difference = MaFP.clone<K, V, T>(mapA);
for (const elem of mapB) {
const entry = _difference.get(elem[0]);
if (entry && entry === elem[1]) {
_difference.delete(elem[0]);
}
}
return _difference;
}

private _map<T>(fn: FnSig<K, V, T>, op: (key: K, value: T) => void): void {
this.forEach((val, key) => {
op(key, fn(val, key, this));
Expand Down Expand Up @@ -272,6 +284,17 @@ export default class MaFP<K, V> extends Map<K, V> {
}
return _difference;
}

difference<T extends Map<K, V>>(otherMap: T): MaFP<K, V> {
const _difference = this.clone();
for (const elem of otherMap) {
const entry = _difference.get(elem[0]);
if (entry && entry === elem[1]) {
_difference.delete(elem[0]);
}
}
return _difference;
}
}

interface KeyOrValue<T> extends IterableIterator<T> {
Expand Down

0 comments on commit bee0101

Please sign in to comment.