@mirei/ts-collections
    Preparing search index...

    Function toLookup

    • Materialises source into a lookup keyed by the provided selector.

      Type Parameters

      Parameters

      Returns ILookup<TKey, TValue>

      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']