Closed malthe closed 1 month ago
Under "Why not have a single function that updates the value if no if the key is mapped?", instead of using a try/finally clause, we could write:
counts.emplace(key, (existing) => existing ?? 0 + 1)
Factory with just insertion:
counts.emplace(key, (existing) => existing ?? someFactory());
Insertion and update, assuming the created value here is always truthy, a reasonable assumption.
counts.emplace(key, (existing) => existing && doSomething(existing) || someFactory())
I don't think these examples are adequately presented in the proposal.
The new direction for the proposal is only looking at the insert use case, not updates.
Under "Why not have a single function that updates the value if no if the key is mapped?", instead of using a try/finally clause, we could write:
Factory with just insertion:
Insertion and update, assuming the created value here is always truthy, a reasonable assumption.
I don't think these examples are adequately presented in the proposal.