distinctBy<K> method

List<T> distinctBy<K>(
  1. K key(
    1. T item
    )
)

Removes duplicates by a field, keeping the first. users.distinctBy((u) => u.id)

Implementation

List<T> distinctBy<K>(K Function(T item) key) {
  final Set<K> seen = <K>{};
  return where((T item) => seen.add(key(item))).toList();
}