ts-iterable-functions
    Preparing search index...

    Function toObjectConst

    • Constructs an object by projecting keys and values from each element of the source iterable.

      Curried version of _toObject.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • K extends PropertyKey

        Property key returned by keySelector.

      • V

        Value returned by valueSelector.

      Parameters

      • keySelector: IndexedSelector<T, K>

        Selector producing the property key for each element along with its index.

      • valueSelector: IndexedSelector<T, V>

        Selector producing the property value for each element along with its index.

      Returns (src: Iterable) => R

      A record keyed by the projected properties with their corresponding values.

      Error Rethrows any error thrown by keySelector or valueSelector.

      const users = [
      { id: "u1", name: "Ada" },
      { id: "u2", name: "Grace" },
      ];
      const lookup = _toObject(
      users,
      (user) => user.id,
      (user) => user.name
      );
      console.log(lookup); // { u1: "Ada", u2: "Grace" }

      or using the curried version:

      const lookup = pipeInto(
      [
      { id: "u1", name: "Ada" },
      { id: "u2", name: "Grace" },
      ],
      toObject(
      (user) => user.id,
      (user) => user.name
      )
      );
      console.log(lookup); // { u1: "Ada", u2: "Grace" }