distinctBy<K> method

List<T> distinctBy<K>(
  1. K keyOf(
    1. T element
    )
)

Returns a list with duplicates removed by keyOf, preserving order.

Implementation

List<T> distinctBy<K>(K Function(T element) keyOf) {
  final seen = <K>{};
  final output = <T>[];
  for (final element in this) {
    final key = keyOf(element);
    if (seen.add(key)) {
      output.add(element);
    }
  }
  return output;
}