MCPcopy Create free account
hub / github.com/denoland/std / forEach

Method forEach

data_structures/unstable_multimap.ts:401–420  ·  view source on GitHub ↗

* 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,
  )

Source from the content-addressed store, hash-verified

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

Callers 15

assertEntriesFunction · 0.80
encodeBase58Function · 0.80
decodeBase58Function · 0.80
base64.tsFile · 0.80
_common16.tsFile · 0.80
hex.tsFile · 0.80
base32.tsFile · 0.80
base64url.tsFile · 0.80
_common32.tsFile · 0.80
_common64.tsFile · 0.80
modeToStringFunction · 0.80
stringifyFunction · 0.80

Calls 1

sliceMethod · 0.45

Tested by

no test coverage detected