intersect method
Returns a new lazy Iterable containing all elements that are contained
by both this collection and the other
collection.
The returned collection preserves the element iteration order of the this collection.
Implementation
Iterable<E> intersect(Iterable<E> other) sync* {
final second = HashSet<E>.from(other);
final output = HashSet<E>();
for (final current in this) {
if (second.contains(current)) {
if (output.add(current)) {
yield current;
}
}
}
}