@mantlebee/ts-data
    Preparing search index...

    Function distinctItems

    • Drops the duplicated items of a list, as a SELECT DISTINCT would: the first occurrence of every item is kept, in its order, the next ones are dropped. Two items are duplicates when they hold the same fields with the same values, whatever the order of the fields, compared through their JSON representation (Dates by their ISO string, nested objects by their content); a primitive or null item is a duplicate of an equal one. Meant to run after projectItems: the duplicates are then found on the projected fields only. The list and its items are never mutated; the result is always a new array.

      Type Parameters

      • TItem = any

      Parameters

      • items: List<TItem>

        Items to deduplicate.

      Returns List<TItem>

      the distinct items.

      const genders = distinctItems(projectItems(users, [{ field: "gender" }]));
      // [{ gender: "F" }, { gender: "M" }]