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
If no value is found, compute a value and insert it.
Return a reference to the value.
For Sets, the expected behavior when they key is not found is to insert into a separate entry, rather than populating the entry associated with the key.
This would provide an easy and efficient path for people looking for this behavior, and avoid misuse of get_or_insert_with, which appears to do the same thing, but doesn't, see #399 and the discussion in #396.
I propose the name get_or_compute rather than following Java, since it makes it harder to accidentally use get_or_insert_with because autocomplete will suggest both.
The text was updated successfully, but these errors were encountered:
I would prefer fixing the existing method rather than adding another which does almost the same thing. This should be discussed in rust-lang/rust#60896.
Inspired by
computeIfAbsent
from Java;For Sets, the expected behavior when they key is not found is to insert into a separate entry, rather than populating the entry associated with the key.
This would provide an easy and efficient path for people looking for this behavior, and avoid misuse of
get_or_insert_with
, which appears to do the same thing, but doesn't, see #399 and the discussion in #396.I propose the name
get_or_compute
rather than following Java, since it makes it harder to accidentally useget_or_insert_with
because autocomplete will suggest both.The text was updated successfully, but these errors were encountered: