combine method

Multiset<E> combine(
  1. Iterable<E> other,
  2. int callback(
    1. E element,
    2. int a,
    3. int b
    )
)

Returns a new Multiset by evaluating callback element-wise for each distinct element of this and other.

Implementation

Multiset<E> combine(
    Iterable<E> other, int Function(E element, int a, int b) callback) {
  if (other is Multiset<E>) {
    final result = Multiset<E>();
    for (final element in {...distinct, ...other.distinct}) {
      result.add(element, callback(element, this[element], other[element]));
    }
    return result;
  } else {
    return combine(Multiset.of(other), callback);
  }
}