You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to #2049, I think we ought to detect attempts to modify hashmaps and other mutable data structures during iteration and fail fast. This should be relatively easy to do thanks to the use of methods to define when iteration is occurring. We can also allow certain kinds of modifications (for example, only the current key) if desired.
The text was updated successfully, but these errors were encountered:
I think this is too restrictive. Updating or removing the item currently being pointed at is extremely useful, and not hard to support. Forcing people to write their own update list when doing a modifying pass over a map would be an admission of defeat wrt usability.
We could allow modification to the current key, but I would be inclined to add a mapValues method instead. It is more efficient (no need to rehash) and more declarative of the intention.
I think this can probably be closed now. Iterating over an owned data structure requires it to be frozen first, and it only ever makes sense to modify a value (not a key) since touching a key would ruin the data structure invariants. Both treemap and hashmap are owned maps and oldmap is deprecated, and all future mutable data structures should be owned.
A method for iterating over the container and modifying the values in-place would definitely be a good idea.
A mutate_values method is added in #5365, and I think that covers 99% of the functionality that would be possible by mutating while iterating. It's possible to allow removing entries while iterating... but it would require unsafe blocks to actually implement it for most of the containers.
Closing this anyway because there's no way to actually mutate it while using normal iteration or lazy iterators since they both freeze it.
Related to #2049, I think we ought to detect attempts to modify hashmaps and other mutable data structures during iteration and fail fast. This should be relatively easy to do thanks to the use of methods to define when iteration is occurring. We can also allow certain kinds of modifications (for example, only the current key) if desired.
The text was updated successfully, but these errors were encountered: