distinctBy<K> method

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

Returns a new list with distinct elements based on key.

users.distinctBy((u) => u.id)

Implementation

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