Feature to get or add value to an associative array.

JN 666total at wp.pl
Mon Apr 16 12:41:07 UTC 2018


On Sunday, 15 April 2018 at 22:52:47 UTC, Giles Bathgate wrote:
> Hi,
>
> 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.



More information about the Digitalmars-d mailing list