union method

Iterable<E> union(
  1. Iterable<E> other
)

Returns a new lazy Iterable containing all distinct elements from both collections.

The returned set preserves the element iteration order of this collection. Those elements of the other collection that are unique are iterated in the end in the order of the other collection.

Implementation

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

  for (var element in other) {
    if (existing.add(element)) yield element;
  }
}