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* {
  var existing = HashSet<R>();
  for (var current in this) {
    if (existing.add(selector(current))) {
      yield current;
    }
  }
}