ts-iterable-functions
    Preparing search index...

    Function _toMap

    • Materializes a sequence into a map keyed by the projected key selector.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • TKey

        Key type returned by keySelector.

      Parameters

      • src: Iterable<T>

        Source iterable to materialize.

      • keySelector: IndexedSelector<T, TKey>

        Projection invoked with each element and index to produce the map key.

      • OptionalmapFactory: MapFactory<TKey>

        Optional factory controlling the concrete map implementation to instantiate.

      Returns Map<TKey, T>

      A map containing one entry per source element keyed by keySelector.

      If keySelector produces the same key more than once.

      const byId = _toMap(
      [
      { id: 1, name: "Ada" },
      { id: 2, name: "Linus" },
      ],
      (person) => person.id,
      (person) => person.name
      );
      console.log(byId.get(2)); // "Linus"
    • Materializes a sequence into a map keyed by the projected key selector.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • TKey

        Key type returned by keySelector.

      • TValue

        Value type stored in the resulting map when valueSelector is supplied.

      Parameters

      • src: Iterable<T>

        Source iterable to materialize.

      • keySelector: IndexedSelector<T, TKey>

        Projection invoked with each element and index to produce the map key.

      • valueSelector: IndexedSelector<T, TValue>

        Optional projection producing the value that should be stored for the key; defaults to the element itself.

      • OptionalmapFactory: MapFactory<TKey>

        Optional factory controlling the concrete map implementation to instantiate.

      Returns Map<TKey, TValue>

      A map containing one entry per source element keyed by keySelector.

      If keySelector produces the same key more than once.

      const byId = _toMap(
      [
      { id: 1, name: "Ada" },
      { id: 2, name: "Linus" },
      ],
      (person) => person.id,
      (person) => person.name
      );
      console.log(byId.get(2)); // "Linus"