mergeMaps<K, V> function

*<Null safety>*

Map<K, V> mergeMaps <K, V>(Map<K, V> map1, Map<K, V> map2, {V value(V, V)})

Implementation

Map<K, V> mergeMaps<K, V>(Map<K, V> map1, Map<K, V> map2,
    {V Function(V, V)? value}) {
  var result = Map<K, V>.of(map1);
  if (value == null) return result..addAll(map2);

  map2.forEach((key, mapValue) {
    result[key] =
        result.containsKey(key) ? value(result[key] as V, mapValue) : mapValue;
  });
  return result;
}