Open
Description
Inspired by computeIfAbsent
from Java;
- Search for a value by key.
- 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.
Metadata
Metadata
Assignees
Labels
No labels