modMap<K, V> static method

Map<K, V> modMap<K, V>(
  1. Map<K, V> initial,
  2. Map<K, V>? add,
  3. Iterable<K>? removeKeys,
  4. bool whereKeys(
    1. K
    )?,
  5. Iterable<V>? removeValues,
  6. bool whereValues(
    1. V
    )?,
)

Implementation

static Map<K,V> modMap<K,V>(Map<K,V> initial, Map<K,V>? add, Iterable<K>? removeKeys, bool Function(K)? whereKeys, Iterable<V>? removeValues, bool Function(V)? whereValues){
  if(add != null || removeKeys != null || whereKeys != null || removeValues != null || whereValues != null){
    Map<K,V> copy = initial;

    if(add != null){
      copy.addAll(add);
    }

    if(removeKeys != null){
      for(K key in removeKeys){
        copy.remove(key);
      }
    }

    if(whereKeys != null){
      copy.removeWhere((k, v) => whereKeys(k));
    }

    if(removeValues != null){
      for(V value in removeValues){
        copy.removeWhere((k, v) => v == value);
      }
    }

    if(whereValues != null){
      copy.removeWhere((k, v) => whereValues(v));
    }

    return copy;
  }

  return initial;
}