distinctBy<K> method
Removes duplicates by key and returns a new list.
Implementation
List<T> distinctBy<K>(K Function(T) key) {
final seen = <K>{};
final result = <T>[];
for (var element in this) {
if (seen.add(key(element))) result.add(element);
}
return result;
}