@szilanor/stream
    Preparing search index...

    Function groupBy

    • Groups the source by a key selector.

      Type Parameters

      • T

        Type of items in the source.

      • TKey

        Type of the key.

      Parameters

      • keySelector: (entry: T) => TKey

        Key selector function.

      Returns CollectorFunction<T, Map<TKey, T[]>>

      Collector that groups the source by a key selector.

      const result = groupBy<number, string>((x) => x % 2 === 0 ? "even" : "odd")([1, 2, 3, 4]);
      console.log(result);
      // Map {
      // 'odd' => [1, 3],
      // 'even' => [2, 4],
      // }