Type of elements within the outer sequence.
Type of elements within the inner sequence.
Type of key produced by the key selectors.
Type of element returned by resultSelector.
The outer sequence.
Sequence whose elements are grouped and joined with the outer elements.
Selector that extracts the join key from each outer element.
Selector that extracts the join key from each inner element.
Projection that combines an outer element with an IEnumerable of matching inner elements.
OptionalkeyComparator: EqualityComparator<TKey, TKey>Optional equality comparator used to match keys. Defaults to the library's standard equality comparison.
A sequence produced by applying resultSelector to each outer element and its matching inner elements.
The inner sequence is enumerated once to build an in-memory lookup before outer elements are processed. Each outer element is then evaluated lazily and preserves the original outer ordering.
const categories = [
{ id: 1, name: 'Fruit' },
{ id: 2, name: 'Vegetable' },
];
const products = [
{ name: 'Apple', categoryId: 1 },
{ name: 'Banana', categoryId: 1 },
{ name: 'Carrot', categoryId: 2 },
];
const joined = groupJoin(
categories,
products,
c => c.id,
p => p.categoryId,
(c, ps) => ({ ...c, products: ps.toArray() })
).toArray();
console.log(joined);
// [
// { id: 1, name: 'Fruit', products: [ { name: 'Apple', categoryId: 1 }, { name: 'Banana', categoryId: 1 } ] },
// { id: 2, name: 'Vegetable', products: [ { name: 'Carrot', categoryId: 2 } ] }
// ]
Correlates each element of the sequence with a collection of matching elements from another sequence.