distinctBy<K> method
Distinct elements by key; keeps first occurrence of each key.
Implementation
@useResult
List<T> distinctBy<K>(K Function(T) keyOf) {
final Set<K> seen = <K>{};
final List<T> result = <T>[];
for (final T element in this) {
final K key = keyOf(element);
if (seen.add(key)) result.add(element);
}
return result;
}