remove method

void remove(
  1. Object? element, [
  2. int occurrences = 1
])

Removes element from the receiver occurrences number of times.

Throws an ArgumentError if occurrences is negative.

Implementation

void remove(Object? element, [int occurrences = 1]) {
  if (occurrences < 0) {
    throw ArgumentError.value(
        occurrences, 'occurrences', 'Negative number of occurrences');
  }
  if (element is E && occurrences > 0) {
    final current = this[element];
    if (current <= occurrences) {
      _container.remove(element);
      _length -= current;
    } else {
      _container[element] = current - occurrences;
      _length -= occurrences;
    }
  }
}