* Executes a provided function once for each individual value in the map, * in insertion order of keys and values. * * Within a bucket, the set of values to visit is fixed at the time the * bucket is entered, so a callback that mutates the current key's list * (via `add()` or `deleteE
(
callbackfn: (this: T, value: V, key: K, map: this) => void,
thisArg?: T,
)
| 399 | * ``` |
| 400 | */ |
| 401 | forEach<T = undefined>( |
| 402 | callbackfn: (this: T, value: V, key: K, map: this) => void, |
| 403 | thisArg?: T, |
| 404 | ): void { |
| 405 | if (typeof callbackfn !== "function") { |
| 406 | throw new TypeError( |
| 407 | `Cannot call MultiMap.prototype.forEach: "callbackfn" is not a function: received ${typeof callbackfn}`, |
| 408 | ); |
| 409 | } |
| 410 | // The bucket is snapshotted before the inner loop so mutations to the |
| 411 | // current key's list (e.g. a callback calling `add()` or splicing via |
| 412 | // `deleteEntry()`) do not extend, truncate, or shift the visit. This |
| 413 | // mirrors the per-bucket contract of `Map.prototype.forEach`. |
| 414 | for (const [key, list] of this.#map) { |
| 415 | const snapshot = list.slice(); |
| 416 | for (let i = 0; i < snapshot.length; i++) { |
| 417 | callbackfn.call(thisArg as T, snapshot[i]!, key, this); |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /** |
| 423 | * Returns an iterator of all `[key, value]` pairs, with each value yielded |
no test coverage detected