Description
There is no method (analogous to java.util.Map.compute
) to use a function to update a key/value in a (mutable) map. There is a replace
method on concurrent.Map
which takes old and new values, allowing you to essentially CAS; however, doing so is cumbersome and probably not efficient. Additionally, it only handles situations where the key is definitely already present in the map; it would be nice to support both situations where there is an existing mapping and where there is not.
This functionality is especially crucial for concurrent maps. Quite often you need to atomically update a key/value in a map, but Scala does not support it. It would also be nice to have such a method on mutable.Map
, but I would consider that less critical. Additionally, there's no reason (AFAICT) for the replace
method not to be defined on mutable.Map
.