distinctBy<R> method

Iterable<E> distinctBy<R>(
  1. R selector(
    1. E element
    )
)

Returns a new lazy Iterable containing only elements from the collection having distinct keys returned by the given selector function.

The elements in the resulting list are in the same order as they were in the source collection.

Implementation

Iterable<E> distinctBy<R>(R Function(E element) selector) sync* {
  final existing = HashSet<R>();
  for (final current in this) {
    if (existing.add(selector(current))) {
      yield current;
    }
  }
}