SohlMap - An extension of Map that returns Itr instances for iterator methods and provides functional transformations with change tracking.

Type Parameters

  • K extends string
  • V

Constructors

  • Create a map, optionally seeded from an array of [key, value] pairs.

    Type Parameters

    • K extends string
    • V

    Parameters

    • Optionalentries: [K, V][]

      Optional initial [key, value] pairs.

    Returns SohlMap<K, V>

Methods

  • Removes all key-value pairs from the map.

    Deletes all entries from the map, resetting its size to zero. After calling this method, map.size === 0 and map.has(key) will return false for all previously stored keys.

    Returns void

    const map = new Map([["a", 1], ["b", 2]]);
    map.clear();
    console.log(map.size); // 0

    This operation is destructive and cannot be undone. It will also trigger persistence logic if your custom map implementation tracks data changes (e.g. SohlMap).

  • Removes the specified key and its associated value from the map.

    If the key exists in the map, the entry is removed and the method returns true. Otherwise, no change is made and false is returned.

    Parameters

    • key: K

      The key of the entry to delete.

    Returns boolean

    true if the entry existed and was removed, or false if the key was not found.

    const map = new Map([["x", 10]]);
    map.delete("x"); // true
    map.delete("y"); // false
  • Returns an iterator over the map's entries.

    Produces an iterable iterator that yields [key, value] pairs from the map, in insertion order.

    This is the default iterator for Map, so it’s equivalent to [Symbol.iterator]().

    Returns Itr<[K, V]>

    An iterable iterator of [K, V] tuples.

    const map = new Map([["id", 42], ["status", "active"]]);
    for (const [key, value] of map.entries()) {
    console.log(`${key} => ${value}`);
    }
  • Test whether every entry satisfies predicate.

    Parameters

    • predicate: (value: V, key: K, map: SohlMap<K, V>) => boolean

      Receives the value, key, and this map.

    Returns boolean

    true if all entries pass (vacuously true when empty).

  • Iterates entries while allowing dynamic expansion.

    Provides a breadth-first iterator over all entries in the collection, including new items added during the iteration itself. This allows your logic to traverse all known items and process new ones as they are introduced dynamically.

    Unlike standard .entries() iteration, which operates over a fixed snapshot of the data, expandingEntries() reflects live state. As entries are added, they are queued and subsequently included in the iteration.

    Returns Itr<[K, V]>

    The mutating iterator.

    • This method guarantees that every element currently in the collection or added while iterating will be visited once.
    • The order is breadth-first, preserving logical consistency when traversal depends on the state of prior elements.
    const map = new SohlMap<string, Mod>();
    map.set("a", new Mod());

    for (const [key, mod] of map.expandingEntries()) {
    if (key === "a") map.set("b", new Mod()); // 'b' will be picked up automatically
    }
  • Collect all values whose entries satisfy predicate.

    Parameters

    • predicate: (value: V, key: K, map: Map<K, V>) => boolean

      Receives the value, key, and backing map.

    Returns V[]

    An array of matching values, in insertion order.

  • Return the first value whose entry satisfies predicate.

    Parameters

    • predicate: (value: V, key: K, map: Map<K, V>) => boolean

      Receives the value, key, and backing map.

    Returns undefined | V

    The matching value, or undefined if none match.

  • Retrieves the value associated with the specified key.

    Returns the value mapped to the given key, or undefined if the key is not present.

    Parameters

    • key: K

      The key to retrieve a value for.

    Returns undefined | V

    The associated value, or undefined if the key is missing.

    const map = new Map([["mode", "hardcore"]]);
    console.log(map.get("mode")); // "hardcore"
    console.log(map.get("missing")); // undefined

    Unlike arrays, using a missing key will not throw an error — you'll simply get undefined.

  • Determines whether a given key exists in the map.

    Returns true if the map contains an entry with the specified key, or false if no such key exists.

    Parameters

    • key: K

      The key to check for existence.

    Returns boolean

    true if the key exists, otherwise false.

    const map = new Map([["id", 100]]);
    console.log(map.has("id")); // true
    console.log(map.has("name")); // false
  • Returns an iterator over the map's keys.

    Produces an iterable iterator that yields each key in the map in insertion order.

    This method allows you to iterate over just the keys without accessing the associated values.

    Returns Itr<K>

    An iterable iterator over the keys in the map.

    const map = new Map([["a", 1], ["b", 2]]);
    for (const key of map.keys()) {
    console.log(key); // "a", then "b"
    }
  • Reduce all entries to a single accumulated value.

    Type Parameters

    • R

      The accumulator/result type.

    Parameters

    • reducer: (accumulator: R, value: V, key: K, map: Map<K, V>) => R

      Receives the running accumulator, value, key, and backing map.

    • initialValue: R

      The starting accumulator value.

    Returns R

    The final accumulated value.

  • Adds or updates a key-value pair in the map.

    Associates the specified value with the given key. If the key already exists, its value is overwritten. If not, a new entry is added.

    Parameters

    • key: K

      The key of the entry to add or update.

    • value: V

      The value to associate with the key.

    Returns this

    The map itself (for chaining).

    const map = new Map<string, number>();
    map.set("a", 1).set("b", 2); // chaining works
    console.log(map.get("b")); // 2

    In custom implementations like SohlMap, set() may also perform runtime type validation or mark the map for persistence.

  • Readonly

    Returns the number of key-value pairs in the map.

    Reflects the total number of entries currently stored in the map. This is a read-only property.

    Returns number

    The number of entries currently stored in the map.

    const map = new Map();
    map.set("x", 1);
    map.set("y", 2);
    console.log(map.size); // 2
  • Test whether at least one entry satisfies predicate.

    Parameters

    • predicate: (value: V, key: K, map: Map<K, V>) => boolean

      Receives the value, key, and backing map.

    Returns boolean

    true if any entry passes, otherwise false.

  • Serialize the map to a plain JSON object keyed by entry key. Each value is serialized via its own toJSON if present, otherwise via defaultToJSON; values that serialize to undefined are omitted.

    Returns JsonValue

    A JSON-safe object representation of the map.

  • Returns an iterator over the map's values.

    Produces an iterable iterator that yields each value in the map in insertion order, ignoring the keys.

    Returns Itr<V>

    An iterable iterator over the values in the map.

    const map = new Map([["x", 10], ["y", 20]]);
    for (const value of map.values()) {
    console.log(value); // 10, then 20
    }
  • Build a SohlMap from a plain object, using each value's fromData if it provides one, otherwise reviving it via defaultFromJSON.

    Type Parameters

    • T

      The value type of the resulting map.

    Parameters

    • data: PlainObject

      Plain object whose entries become map entries.

    Returns SohlMap<string, T>

    A new SohlMap keyed by the object's own keys.