distinctBy<K> method

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

Returns distinct elements by key.

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

Implementation

Iterable<T> distinctBy<K>(K Function(T) key) sync* {
  final seen = <K>{};
  for (final e in this) {
    if (seen.add(key(e))) yield e;
  }
}