Interface IMapMutable<K, V>

A mutable map.

It is a wrapper around the in-built Map type, but adds roughly the same API as IMapImmutable.

interface IMapMutable<K, V> {
    add(...itemsToAdd: EitherKey<K, V>): void;
    clear(): void;
    delete(key: K): void;
    entries(): IterableIterator<readonly [K, V]>;
    get(key: K): undefined | V;
    has(key: K): boolean;
    isEmpty(): boolean;
    set(key: K, value: V): void;
    values(): IterableIterator<V>;
}

Type Parameters

  • K

    Type of map keys. Typically string

  • V

    Type of stored values

Hierarchy

  • IMapBase<K, V>
    • IMapMutable

Methods

  • Adds one or more items to map

    Can add items in the form of [key,value] or {key, value}.

    Parameters

    Returns void

    map.set(`hello`, `samantha`);
    map.add([`hello`, `samantha`]);
    map.add({key: `hello`, value: `samantha`})
  • Clears map

    Returns void

  • Deletes an item by key

    Parameters

    • key: K

    Returns void

  • Iterates over entries (consisting of [key,value])

    Returns IterableIterator<readonly [K, V]>

    for (const [key, value] of map.entries()) {
    // Use key, value...
    }
  • Gets an item by key

    Parameters

    • key: K

    Returns undefined | V

    const item = map.get(`hello`);
    
  • Returns true if map contains key

    Parameters

    • key: K

    Returns boolean

    if (map.has(`hello`)) ...
    
  • Returns true if map is empty

    Returns boolean

  • Sets a value to a specified key

    Parameters

    • key: K
    • value: V

    Returns void

  • Returns IterableIterator<V>