Open
Description
AFAIK, there isnt an easy way to get and remove an entry from a Map in a single lookup. remove
removes it but doesnt expose the removed value. The desired operation would return a pair of the updated map, and the removed value (if any) wrapped in an Option.
In performance-critical code, a double lookup is not acceptable for something that can be readily done in a single visit to the map.
The operation can be performed in a single pass using updatedWith
but the resulting code is non-obvious and involves a transient var
. It's not the sort of code clients of the API should need to be writing.