Class ReadonlyMultiKeyMap<K, V>

Map with entries that contains multiple keys and a single value

David Hsing

Type Parameters

  • K
  • V

Implements

  • Omit<ReadonlyMap<K[], V>,
        | "forEach"
        | "get"
        | "has"
        | "entries"
        | "keys"
        | "values">

Constructors

  • Construct a readonly multi key map instance

    Type Parameters

    • K
    • V

    Parameters

    Returns ReadonlyMultiKeyMap<K, V>

    const map = new ReadonlyMultiKeyMap([
    [['row1', 'col1'], 'foo']
    ]);

Accessors

  • get [toStringTag](): string
  • Returns the string representation of the map identifier ('ReadonlyMultiKeyMap')

    Returns string

    the string representation of the map identifier

  • get size(): number
  • Returns the size of map

    Returns number

    the size of map

Methods

  • Response for returning the list of keys/value to iterate

    Returns IterableIterator<[K[], V], any, any>

    for (const [keys, value] of map) {
    console.log(value);
    }
  • Returns the keys/value entries of the map

    Returns [K[], V][]

    the keys/value entries of the map

  • Processes each entry in the map

    Parameters

    • callback: ((value: V, keys: K[]) => void)

      a callback function that processes each entry

        • (value, keys): void
        • Parameters

          • value: V
          • keys: K[]

          Returns void

    • OptionalthisArg: any

      any instance to retrieve 'this' reference in the callback function

    Returns void

    map.forEach((value, keys) => {
    console.log(value);
    });
  • Processes each entry in the map with breakable capability

    Parameters

    • callback: ((value: V, keys: K[]) => boolean)

      a callback function that processes each entry. Returning false indicates to break the map iteration

        • (value, keys): boolean
        • Parameters

          • value: V
          • keys: K[]

          Returns boolean

    • OptionalthisArg: any

      any instance to retrieve 'this' reference in the callback function

    Returns void

    map.forEachBreakable((value, keys) => {
    return true;
    });
  • Processes each entry in the map with index capability

    Parameters

    • callback: ((value: V, keys: K[], index: number) => void)

      a callback function that processes each entry

        • (value, keys, index): void
        • Parameters

          • value: V
          • keys: K[]
          • index: number

          Returns void

    • OptionalthisArg: any

      any instance to retrieve 'this' reference in the callback function

    Returns void

    map.forEachIndexing((value, keys, index) => {
    console.log(index);
    });
  • Returns the value of the given keys

    Parameters

    • keys: K[]

      the keys to retrieve

    • Optionaldefaults: V

      the default value if not found

    Returns undefined | V

    the value of the given keys

    const map = ReadonlyMultiKeyMap.of([
    [['row1', 'col1'], 'foo']
    ]);
    map.get(['row1', 'col1']); // 'foo'
    map.get(['row2', 'col2'], 'bar'); // 'bar'
  • Returns whether the map contains all the given keys

    Parameters

    • keys: K[][]

      the keys to check

    • exact: boolean = true

      whether matching entry values exactly

    Returns boolean

    whether the map contains all the given keys

    const map = ReadonlyMultiKeyMap.of([
    [['row1', 'col1'], 'foo']
    ]);
    map.hasAllKeys([['row1', 'col1'], ['row2', 'col2']]); // false
  • Returns whether the map contains all the given values

    Parameters

    • values: V[]

      the values to check

    Returns boolean

    whether the map contains all the given values

    map.hasAllValues(['foo', 'bar']);
    
  • Returns whether the map contains any of the given keys

    Parameters

    • keys: K[][]

      the keys to check

    • exact: boolean = true

      whether matching entry values exactly

    Returns boolean

    whether the map contains any of the given keys

    const map = ReadonlyMultiKeyMap.of([
    [['row1', 'col1'], 'foo']
    ]);
    map.hasAnyKeys([['row1', 'col1'], ['row2', 'col2']]); // true
  • Returns whether the map contains any of the given values

    Parameters

    • values: V[]

      the values to check

    Returns boolean

    whether the map contains any of the given values

    const map = ReadonlyMultiKeyMap.of([
    [['row1', 'col1'], 'foo']
    ]);
    map.hasAnyValues(['foo', 'bar']); // true
  • Returns whether the map contains the given keys

    Parameters

    • keys: K[]

      the keys to check

    • exact: boolean = true

      whether matching entry values exactly

    Returns boolean

    whether the map contains the given key

    map.hasKey(['row1', 'col1']);
    
  • Returns whether the map contains the given keys/value pair

    Parameters

    • keys: K[]

      the keys to check

    • value: V

      the value to check

    Returns boolean

    whether the map contains the given keys/value pair

    const map = ReadonlyMultiKeyMap.of([
    [['row1', 'col1'], 'foo']
    ]);
    map.hasKeyValue(['row1', 'col1'], 'foo'); // true
    map.hasKeyValue(['row1', 'col1'], 'bar'); // false
  • Returns whether the map contains the given value

    Parameters

    • value: V

      the value to check

    Returns boolean

    whether the map contains the given value

    const map = ReadonlyMultiKeyMap.of([
    [['row1', 'col1'], 'foo']
    ]);
    map.hasValue('foo'); // true
    map.hasValue('bar'); // false
  • Returns whether the map is empty

    Returns boolean

    whether the map is empty

  • Returns whether the map is not empty

    Returns boolean

    whether the map is not empty

  • Returns the keys array of the map

    Returns K[][]

    the keys array of the map

  • Returns the string representation of the map elements

    Returns string

    the string representation of the map elements

    const map = ReadonlyMultiKeyMap.of([
    [['row1', 'col1'], 'foo'],
    [['row2', 'col2'], 'bar']
    ]);
    console.log(map.toString()); // '[row1,col1]:foo;[row2,col2]:bar'
  • Returns the values of the map

    Returns V[]

    the values of the map

  • Construct a readonly multi key map instance

    Type Parameters

    • K
    • V

    Parameters

    Returns ReadonlyMultiKeyMap<K, V>

    a readonly multi key map instance

    const map = ReadonlyMultiKeyMap.of([
    [['row1', 'col1'], 'foo']
    ]);