@szilanor/stream
    Preparing search index...

    Function toMap

    • Converts the source to a map.

      Type Parameters

      • T

        Type of items in the source.

      • TKey

        Type of the key.

      • TValue

        Type of the value.

      Parameters

      • keySelector: (entry: T) => TKey

        Key selector function.

      • valueSelector: (entry: T) => TValue

        Value selector function.

      Returns CollectorFunction<T, Map<TKey, TValue>>

      Collector that converts the source to a map.

      const result = toMap<number, string, number>((x) => x.toString(), (x) => x * 2)([1, 2, 3]);
      console.log(result);
      // Map {
      // '1' => 2,
      // '2' => 4,
      // '3' => 6,
      // }