distinct method

Iterable<E> distinct()

Returns a new lazy Iterable containing only distinct elements from the collection.

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

Implementation

Iterable<E> distinct() sync* {
  var existing = HashSet<E>();
  for (var current in this) {
    if (existing.add(current)) {
      yield current;
    }
  }
}