filterNotTo<M extends KtMutableMap> method Null safety

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, but will be checked at runtime. M actually is expected to be M extends KtMutableMap<K, V>

@return the destination map.


// TODO Change to `M extends KtMutableMap<K, V>` once 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."
    return true;
  for (final element in iter) {
    if (!predicate(element)) {
      destination.put(element.key, element.value);
  return destination;