Function transformMap

Like Array.map, but for a Map. Transforms from Map<K,V> to Map<K,R>, returning as a new Map.

const mapOfStrings = new Map();
mapOfStrings.set(`a`, `10`);
mapOfStrings.get(`a`); // Yields `10` (a string)

// Convert a map of string->string to string->number
const mapOfInts = transformMap(mapOfStrings, (value, key) => parseInt(value));

mapOfInts.get(`a`); // Yields 10 (a proper number)

If you want to combine values into a single object, consider instead mapToObjectTransform.

  • Type Parameters

    • K

      Type of keys (generally a string)

    • V

      Type of input map values

    • R

      Type of output map values

    Parameters

    • source: ReadonlyMap<K, V>
    • transformer: ((value: V, key: K) => R)
        • (value, key): R
        • Parameters

          • value: V
          • key: K

          Returns R

    Returns Map<K, R>