ts-iterable-functions
    Preparing search index...

    Function _distinctBy

    • Emits source elements while removing duplicates identified by the selector key.

      Type Parameters

      • T

        Element type produced by the source iterable.

      • TKey

        Key type returned by the selector.

      Parameters

      • src: Iterable<T>

        Source iterable enumerated for distinct values.

      • selector: IndexedSelector<T, TKey>

        Selector producing a comparison key for each element.

      • setFactory: SetFactory<TKey> = ...

        Optional factory supplying the set used to track seen keys.

      Returns Iterable<T>

      A deferred iterable yielding the first element for each unique key.

      Error Rethrows any error thrown by selector or setFactory.

      const users = [
      { id: 1, name: "Ada" },
      { id: 1, name: "Ada" },
      { id: 2, name: "Grace" },
      ];
      const unique = [..._distinctBy(users, (user) => user.id)];
      console.log(unique); // [{ id: 1, name: "Ada" }, { id: 2, name: "Grace" }]

      or using the curried version:

      const unique = [
      ...pipeInto(
      [
      { id: 1, name: "Ada" },
      { id: 1, name: "Ada" },
      { id: 2, name: "Grace" },
      ],
      distinctBy((user) => user.id)
      ),
      ];
      console.log(unique); // [{ id: 1, name: "Ada" }, { id: 2, name: "Grace" }]