distinctBy method

List<T> distinctBy(
  1. dynamic identity(
    1. T e
    )
)

Implementation

List<T> distinctBy(dynamic Function(T e) identity) {
  final seen = <dynamic>{};
  final result = <T>[];

  for (final e in this) {
    final id = identity(e);

    if (!seen.contains(id)) {
      seen.add(id);
      result.add(e);
    }
  }

  return result;
}