Type of elements within source.
Type of key returned by keySelector.
Type of value returned by valueSelector.
The source iterable.
Selector used to derive the key for each element.
Selector used to derive the value for each element.
OptionalkeyComparator: OrderComparator<TKey, TKey>Optional order comparator used to compare keys in the resulting lookup.
A lookup grouping the projected values by key.
The entire sequence is enumerated immediately. Elements within each group preserve their original order and the groups are cached for repeated enumeration.
const products = [
{ name: 'Apple', category: 'Fruit' },
{ name: 'Banana', category: 'Fruit' },
{ name: 'Carrot', category: 'Vegetable' },
];
const lookup = toLookup(products, p => p.category, p => p.name);
console.log(lookup.get('Fruit').toArray()); // ['Apple', 'Banana']
console.log(lookup.get('Vegetable').toArray()); // ['Carrot']
Materialises source into a lookup keyed by the provided selector.