union method

Map<K, V> Function(Map<K, V> map) union(
  1. Eq<K> eq,
  2. Magma<V> combine
)

Combine the key/value of two Map using combine where the key is the same.

Implementation

Map<K, V> Function(Map<K, V> map) union(Eq<K> eq, Magma<V> combine) =>
    (Map<K, V> map) => map.foldLeftWithKey<Map<K, V>>(Order.allEqual())(
          this,
          (acc, key, value) => acc
              .modifyAt(eq)(
                key,
                (v) => combine(v, value),
              )
              .getOrElse(
                () => acc.upsertAt(eq)(key, value),
              ),
        );