intersection method

Multiset<E> intersection(
  1. Iterable<Object?> other
)

Returns a new Multiset with the elements that are in the receiver as well as those in other.

Implementation

Multiset<E> intersection(Iterable<Object?> other) {
  if (other is Multiset) {
    final result = Multiset<E>();
    for (final element in distinct) {
      result.add(element, min(this[element], other[element]));
    }
    return result;
  } else {
    return intersection(Multiset.of(other));
  }
}