Unique<E, Id> extension

An extension on List that provides functionality for handling unique elements based on a specified identifier type Id.

This extension can be used to add utility methods for extracting or filtering unique elements from a list, where uniqueness is determined by a property or identifier of type Id.

Type Parameters:

  • E: The type of elements in the list.
  • Id: The type used to determine uniqueness (e.g., a field or property of E).

Example usage:

final users = [User(id: 1), User(id: 2), User(id: 1)];
final uniqueUsers = users.uniqueBy((user) => user.id);
on

Methods

unique([Id id(E element)?, bool inplace = true]) List<E>

Available on List<E>, provided by the Unique extension

Returns a new list containing unique elements based on the provided id function.