Element type produced by the source iterable.
Key type generated by the key selector.
Element type produced by the element selector for each group.
Result type emitted by the group projection.
Source iterable enumerated sequentially for grouping.
Selector producing a key for each source element.
Selector producing the element stored for each group member.
Projection invoked with the key and grouped elements.
OptionalequalityComparer: (a: TKey | undefined, b: TKey | undefined) => booleanOptional key comparer; defaults to strict equality when omitted.
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"] }
// ]
Groups adjacent elements that share an equal key and projects each group into a result.