is there a `Map<K, V>.putAllWith(other: Map&...
# announcements
l
is there a
Map<K, V>.putAllWith(other: Map<K, V>, remappingFunction: (V, V) -> V): Map<K,V>
equivalent?
d
With
Map
is mutable?
Nvm.
l
yes, with map mutable. That seems to be what I'm looking for, thanks!
or no, it actually isn't. what i'm looking for is this:
Copy code
/** merge another map into this map,
 * applying the given remapping function too the two values if there is a key-conflict. */
fun <K, V> MutableMap<K, V>.putAllWith(other: Map<K, V>, remappingFn: (V, V) -> V) = other.forEach { (k, v) ->
    merge(k, v, remappingFn)
}
d
I don't think that can be done with a single function.
l
I guess I'll propose this in the
stdlib
channel then, i've needed it several times and it seems like a good addition!
👍 1