ts-iterable-functions
    Preparing search index...

    Function _toLookup

    • Groups elements of a sequence by key, returning a map of iterables per key.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • TKey

        Key type returned by keySelector.

      Parameters

      • src: Iterable<T>

        Source iterable to partition.

      • keySelector: IndexedSelector<T, TKey>

        Projection producing the lookup key for each element.

      • OptionalmapFactory: MapFactory<TKey>

        Optional factory controlling the concrete map implementation that backs the lookup.

      Returns Map<TKey, Iterable<T, any, any>>

      A map in which each key maps to an iterable of the grouped values.

      const lookup = _toLookup(
      ["a", "aa", "bbb"],
      (value) => value.length
      );
      console.log([...lookup.entries()].map(([k, v]) => [k, [...v]]));
      // [[1, ["a"]], [2, ["aa"]], [3, ["bbb"]]]
    • Groups elements of a sequence by key, returning a map of iterables per key.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • TKey

        Key type returned by keySelector.

      • TValue

        Value type stored in each lookup entry when valueSelector is supplied.

      Parameters

      • src: Iterable<T>

        Source iterable to partition.

      • keySelector: IndexedSelector<T, TKey>

        Projection producing the lookup key for each element.

      • valueSelector: IndexedSelector<T, TValue>

        Optional projection producing the value to store per key; defaults to the element itself.

      • OptionalmapFactory: MapFactory<TKey>

        Optional factory controlling the concrete map implementation that backs the lookup.

      Returns Map<TKey, Iterable<TValue, any, any>>

      A map in which each key maps to an iterable of the grouped values.

      const lookup = _toLookup(
      ["a", "aa", "bbb"],
      (value) => value.length
      );
      console.log([...lookup.entries()].map(([k, v]) => [k, [...v]]));
      // [[1, ["a"]], [2, ["aa"]], [3, ["bbb"]]]