-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Consider a getAndRemove
operation on Map
s
#86
Comments
I assume you're referring to |
|
As I mentioned above, it can be done in one pass using the existing Here's an example (verbatim from my week3 solution of the Effective Scala course)
|
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 transientvar
. It's not the sort of code clients of the API should need to be writing.The text was updated successfully, but these errors were encountered: