filterNotTo<M extends KtMutableMap> method

M filterNotTo<M extends KtMutableMap>(
  1. M destination,
  2. bool predicate(
    1. KtMapEntry<K, V> entry
    )
)

Appends all entries not matching the given predicate into the given destination.

destination is not type checked by the compiler due to https://github.com/dart-lang/sdk/issues/35518, but will be checked at runtime. M actually is expected to be M extends KtMutableMap<K, V>

@return the destination map.

Implementation

// TODO Change to `M extends KtMutableMap<K, V>` once https://github.com/dart-lang/sdk/issues/35518 has been fixed
M filterNotTo<M extends KtMutableMap<dynamic, dynamic>>(
    M destination, bool Function(KtMapEntry<K, V> entry) predicate) {
  assert(() {
    if (destination is! KtMutableMap<K, V> && mutableMapFrom<K, V>() is! M) {
      throw ArgumentError("filterNotTo destination has wrong type parameters."
          "\nExpected: KtMutableMap<$K, $V>, Actual: ${destination.runtimeType}"
          "\ndestination (${destination.runtimeType}) entries aren't subtype of "
          "map ($runtimeType) entries. Entries can't be copied to destination."
          "\n\n$kBug35518GenericTypeError");
    }
    return true;
  }());
  for (final element in iter) {
    if (!predicate(element)) {
      destination.put(element.key, element.value);
    }
  }
  return destination;
}