ts-iterable-functions
    Preparing search index...

    Function _groupAdjacent

    • Groups adjacent elements that share an equal key and projects each group into a result.

      Type Parameters

      • TSource

        Element type produced by the source iterable.

      • TKey

        Key type generated by the key selector.

      • TElement

        Element type produced by the element selector for each group.

      • TResult

        Result type emitted by the group projection.

      Parameters

      • src: Iterable<TSource>

        Source iterable enumerated sequentially for grouping.

      • keySelector: IndexedSelector<TSource, TKey>

        Selector producing a key for each source element.

      • elementSelector: IndexedSelector<TSource, TElement>

        Selector producing the element stored for each group member.

      • resultSelector: (key: TKey, items: Iterable<TElement>) => TResult

        Projection invoked with the key and grouped elements.

      • OptionalequalityComparer: (a: TKey | undefined, b: TKey | undefined) => boolean

        Optional key comparer; defaults to strict equality when omitted.

      Returns Iterable<TResult>

      A deferred iterable emitting one projected result for each run of equal keys.

      const result = [..._groupAdjacent(
      [1, 1, 2, 3, 3],
      (value) => value,
      (value) => value * 2,
      (key, items) => ({ key, doubled: [...items] })
      )];
      console.log(result);
      // [
      // { key: 1, doubled: [2, 2] },
      // { key: 2, doubled: [4] },
      // { key: 3, doubled: [6, 6] }
      // ]

      or using the curried version:

      const result = pipeInto(
      ["a", "a", "b"],
      groupAdjacent(
      (value) => value,
      (value) => value.toUpperCase(),
      (key, items) => ({ key, items: [...items] })
      )
      );
      console.log([...result]);
      // [
      // { key: "a", items: ["A", "A"] },
      // { key: "b", items: ["B"] }
      // ]