distinctBy method

List<T> distinctBy(
  1. bool f(
    1. T
    )
)

Distinct the list by f. Returns a new list with distinct elements based on f.

Implementation

List<T> distinctBy(bool Function(T) f) {
  final list = <T>[];
  for (final item in this) {
    if (!list.any((e) => f(e))) {
      list.add(item);
    }
  }
  return list;
}