MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeCompareMap

Function makeCompareMap

packages/effect/src/Equal.ts:361–382  ·  view source on GitHub ↗
(keyEquivalence: Equivalence<K>, valueEquivalence: Equivalence<V>)

Source from the content-addressed store, hash-verified

359
360/** @internal */
361export function makeCompareMap<K, V>(keyEquivalence: Equivalence<K>, valueEquivalence: Equivalence<V>) {
362 return function compareMaps(self: Iterable<[K, V]>, that: Iterable<[K, V]>): boolean {
363 const thatEntries = Array.from(that)
364 for (const [selfKey, selfValue] of self) {
365 let found = false
366 for (let i = 0; i < thatEntries.length; i++) {
367 const [thatKey, thatValue] = thatEntries[i]
368 if (keyEquivalence(selfKey, thatKey) && valueEquivalence(selfValue, thatValue)) {
369 thatEntries[i] = thatEntries[thatEntries.length - 1]
370 thatEntries.pop()
371 found = true
372 break
373 }
374 }
375 if (!found) {
376 return false
377 }
378 }
379
380 return true
381 }
382}
383
384const compareMaps = makeCompareMap(compareBoth, compareBoth)
385

Callers 1

Equal.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected