On Sunday, 15 April 2018 at 22:52:47 UTC, Giles Bathgate wrote:

I wanted a way to lazily insert a value into an associative array, and I am proposing a new function called getOrAdd in https://github.com/dlang/druntime/pull/2162

I am not sure if it's a good idea to combine accessor and insertion in a same method call. Is it really such a big overhead to do "if in assocarray then take else create new"? It's only one additional "in", but makes the code more explicit and clear. I think in most cases, you will want to check if you are dealing with a fetched object or a default created one, so that will complicate the function even further.

Reply via email to